在以下示例中,我想从 Flickr JSON 访问 ID 值(见下文):
{
page = 1;
pages = 336567;
perpage = 20;
photo = (
{
farm = 6;
id = 10573655046;
isfamily = 0;
isfriend = 0;
ispublic = 1;
owner = "32491986@N08";
secret = 91349d9115;
server = 5533;
title = DSC09356;
},
{
farm = 8;
id = 10573936633;
isfamily = 0;
isfriend = 0;
ispublic = 1;
owner = "32491986@N08";
secret = 6abdcaa69e;
server = 7295;
title = DSC09118;
}
);
所以我尝试尝试使用以下模式
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
if(json == nil){
NSLog(@"NULL");
}else
NSLog(@" WORKED");
NSArray* flickrPics = [json objectForKey:@"photos"];
NSLog(@"Details: %@", flickrPics); //works
NSDictionary* lastUpload = [flickrPics objectAtIndex:0];
//fails on that line but the idea would have been to then
NSNumber* id = lastUpload[@"photo"][@"id"];
这是错误
2013-10-30 13:43:50.534 JSON1[1508:1303] -[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x8ab3820
那么为什么会出现这个错误(我在不同的 JSON 对象上使用了这个模式)那么如何访问 id 呢?