Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

iphone - 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 alloc] 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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...