解析一些返回的JSON時遇到了一些麻煩。我對JSON的工作還很陌生。我試圖從第一個JSON數組元素中獲取公司名稱。我有一種感覺,我很困惑使用NSMutabeArray和NSMutableDictionary。我得到的是null。任何想法我做錯了什麼?返回null的JSON
NSString *url = @"http://www.google.com/finance/info?infotype=infoquoteall&q=C,JPM,AIG,AAPL";
NSData* data = [NSData dataWithContentsOfURL:
[NSURL URLWithString: url]];
//parse out the json data
NSError* error;
NSMutableArray* json = [NSJSONSerialization
JSONObjectWithData:data //1
options:kNilOptions
error:&error];
NSString* companyName = [[json objectAtIndex:0] objectForKey:@"name"] ; //Where I need some help
NSLog(@"we got %@", companyName);
通過記錄下列值來幫助我們找出問題出現的地方:JSON字符串本身,'json','[json objectAtIndex:0]'。 – 2012-07-24 05:11:15