Objective c 嵌套objectForKey调用work,但等效值forkey调用不';T
我有一本代表Flickr照片的词典 照片的描述如下所示:Objective c 嵌套objectForKey调用work,但等效值forkey调用不';T,objective-c,ios6,key-value-coding,Objective C,Ios6,Key Value Coding,我有一本代表Flickr照片的词典 照片的描述如下所示: { accuracy = 16; context = 0; dateupload = 1355106635; description = { "_content" = "Barclays Center Arena\nAtlantic Yards\nProspect Heights\nBrooklyn, New York"; }; farm = 9; "geo_
{
accuracy = 16;
context = 0;
dateupload = 1355106635;
description = {
"_content" = "Barclays Center Arena\nAtlantic Yards\nProspect Heights\nBrooklyn, New York";
};
farm = 9;
"geo_is_contact" = 0;
"geo_is_family" = 0;
"geo_is_friend" = 0;
"geo_is_public" = 1;
id = 8260097924;
isfamily = 0;
isfriend = 0;
ispublic = 1;
latitude = "40.681786";
longitude = "-73.972545";
originalformat = jpg;
originalsecret = cd1bdd846a;
owner = "62968578@N07";
ownername = atlanticyardswebcam02;
"place_id" = "uUNC_q9TWr1vROR4wA";
secret = 320e308baa;
server = 8502;
tags = "newyork brooklyn construction prospectheights atlanticyards forestcityratner block1129 barclayscenterarena";
title = "Barclays Center Arena - 20121209_2128";
woeid = 28751452;
}
NSString *photoDescription = [[photo objectForKey:@"description"] objectForKey:@"_content"];
如果我通过嵌套的objectForKey调用获得描述,它就会工作。也就是说,像这样:
{
accuracy = 16;
context = 0;
dateupload = 1355106635;
description = {
"_content" = "Barclays Center Arena\nAtlantic Yards\nProspect Heights\nBrooklyn, New York";
};
farm = 9;
"geo_is_contact" = 0;
"geo_is_family" = 0;
"geo_is_friend" = 0;
"geo_is_public" = 1;
id = 8260097924;
isfamily = 0;
isfriend = 0;
ispublic = 1;
latitude = "40.681786";
longitude = "-73.972545";
originalformat = jpg;
originalsecret = cd1bdd846a;
owner = "62968578@N07";
ownername = atlanticyardswebcam02;
"place_id" = "uUNC_q9TWr1vROR4wA";
secret = 320e308baa;
server = 8502;
tags = "newyork brooklyn construction prospectheights atlanticyards forestcityratner block1129 barclayscenterarena";
title = "Barclays Center Arena - 20121209_2128";
woeid = 28751452;
}
NSString *photoDescription = [[photo objectForKey:@"description"] objectForKey:@"_content"];
这很笨拙,我的理解是这也应该有效:
NSString *photoDescription_kv = [photo valueForKey:@"description._content"];
但是,valueForKey始终返回null
我做错了什么?应该改用valueForKeyPath
NSString *photoDescription_kv = [photo valueForKeyPath:@"description._content"];
应改为使用valueForKeyPath
NSString *photoDescription_kv = [photo valueForKeyPath:@"description._content"];