2012-12-10 66 views
0

我有一個代表Flickr照片的NSDictionary。嵌套的objectForKey調用工作,但等價的valueForKey調用不?

照片的描述看起來是這樣的:

{ 
    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 = "[email protected]"; 
    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。

我在做什麼錯?

回答

5

應改爲使用valueForKeyPath。

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