1

Just for information, i'm a newbie in Xcode Dev.

I have a problem with displaying data from a web service in a UITableView.

I use ASIHttpRequest to construct a HTTP request to get JSON data from a Web server. My request is constructed like this (with a JSON parameter and implemented in viewDidLoad methods) :

 NSString *jsonString = @"login";


NSString *URL = @"MyURL";

NSURL *filactuURL = [NSURL URLWithString:URL];


ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:filactuURL];
[request  setRequestMethod:@"POST"];
[request addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"]; 
[request addRequestHeader:@"Content-Type" value:@"application/json"];
[request appendPostData:[jsonString  dataUsingEncoding:NSUTF8StringEncoding]]; 



[request setDelegate:self];


[request startAsynchronous];

Then, I get the response with this code :

-(void) requestFinished: (ASIHTTPRequest *) request {

    NSString *theJSON = [request responseString];

    SBJsonParser *parser = [[SBJsonParser alloc] init];

    id message = [parser objectWithString:theJSON error:nil];

    if ([message isKindOfClass:[NSDictionary class]])
    {

        //Not used

    }
    else if ([message isKindOfClass:[NSArray class]])
    {
        for(int i = 0; i < [message count]; i++)
        {
            for (NSDictionary *dic in message) {

                Message *messsage = [[Message alloc] init];

                messsage.expediteur = [dic objectForKey:@"expediteur"];

                messsage.titre = [dic objectForKey:@"titre"] ;

                messsage.date = [dic objectForKey:@"date"] ;

                messsage.contenu = [dic objectForKey:@"contenu"] ;

                [tableau addObject:messsage];

                [messsage release];

            }

        }
      [theJSON release];   
    }  
}

The server send me JSON data, I parse it using SBJSon and I populate a Message object. This object will be used to populate cells of a TableView. After getting the response, here's the problem : cells are empty, but the app doesn't crash and i got no error.

I've tried with hard stored JSON data, it works fine, the cells are filled.

Thanks for helping

Serviet
  • 71
  • 1
  • 7

1 Answers1

-1

I have done similar type of program which can be found here

The only problem is that I get records of first page only. But I think this example will help in solving your problem.

Community
  • 1
  • 1
Itaws
  • 330
  • 1
  • 22