我在解析这个 JSON 时遇到了一个小问题
{
"@attributes": {
"date": "23-12-2012"
},
"data": [
{
"ft_link": "google",
"title": "CEO"
},
{
"ft_link": "Yahoo",
"title": "CEO"
}
]
}
我试图得到所有的“标题”项目。
NSError *jsonError = nil;
id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&jsonError];
NSDictionary *jsonDictionary = (NSDictionary *)jsonObject;
NSLog(@"%@", [jsonDictionary objectForKey:@"data"]);
这会记录整个 JSON。但现在我想解析所有“标题”项目。所以我尝试了:
NSLog(@"%@", [jsonDictionary objectForKey:@"data"] objectForKey:@"title"]);
但后来它崩溃了,我怎样才能正确解析它?
迷恋;撞车;崩溃:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x91583c0'