简体   繁体   中英

extracting value out of NSDictionary

I have a NSDictionary called data and when I print using NSLog it gives me:

DATA IS {
    aps =     {
        alert = "aherlambang liked your photo";
        badge = 1;
    };
    "media_id" = "220516456473412852_29088696";
}

I tried to extract the media_id by doing:

 NSLog(@"DATA IS %@ MEDIA ID IS %@", userInfo, [userInfo valueForKey:@"media-id"]);

but it always gives me null. Why is this?

Your key in the data is "media_id" , and you're trying to use the key "media-id" .

Change "media-id" to "media_id" and you should be able to read your dictionary.

 NSLog(@"DATA IS %@ MEDIA ID IS %@", userInfo, [userInfo valueForKey:@"media_id"]);

也许是因为您的字典被命名为data,而您正在访问的用户是不是?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM