JSON parsing error
I am trying to parse some JSON. I've passed a constant key value and a string - butI'm receivng 16 objects in the statuses
array and 20 objects in ststuses1
.
Are any of the parsing steps wrong?
I have included the code for the JSON parser.
Thanks in advance.
SBJSON *parser = [[SBJSON allo开发者_如何转开发c] init];
NSString *urlString =[NSString stringWithFormat:@"http://api.shiki.com/api/serch?key=%@&q=%@",apiKey, string];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL: url];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSMutableArray *statuses = nil;
statuses = [[NSMutableArray alloc]init];
statuses = [parser objectWithString:json_string error:nil];
NSMutableArray *statuses0 = [[statuses valueForKey:@"offers"] valueForKey:@"offer"];
NSLog(@"Array Contents: %@", statuses0);
I guess that's not the only syntax-error in your code...
Please define statuses and ststuses1. I can only see statuses (redefined 2 times) and statuses0. Also please post a sample of the json-data you're parsing so I can take a look at it.
精彩评论