嵌套的objectForKey调用工作,但是等效的valueForKey调用没有?

时间:2012-12-10 03:03:23

标签: objective-c ios6 key-value-coding

我有一个代表Flickr照片的NSDictionary。

照片的描述如下:

{
    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;
}

如果我通过嵌套的objectForKey调用获得描述,它就可以工作。即,像这样:

NSString *photoDescription = [[photo objectForKey:@"description"] objectForKey:@"_content"];

那是笨重的,我的理解是这也应该有效:

NSString *photoDescription_kv = [photo valueForKey:@"description._content"];

但是,valueForKey始终返回null。

我做错了什么?

1 个答案:

答案 0 :(得分:5)

应改为使用valueForKeyPath。

NSString *photoDescription_kv = [photo valueForKeyPath:@"description._content"];