5

我正在向 Facebook 提出以下简单请求。我的目标是获取所有用户相册的名称:

[[AppDelegate sharedDelegate].facebook requestWithGraphPath:@"me/albums" andDelegate:[AppDelegate sharedDelegate]];

然后,我从服务器收到 JSON 响应,如下所示:

data =     (
            {
        "can_upload" = 1;
        count = 4;
        "cover_photo" = 321491374598618;
        "created_time" = "2012-06-04T21:46:23+0000";
        from =             {
            id = 100002132746588;
            name = "Owner....";
        };
        id = 321491371265285;
        link = "http://www.facebook.com/album.php?fbid=321491371265285&id=100002132746588&aid=73680";
        name = "Photos";
        privacy = custom;
        type = normal;
        "updated_time" = "2012-06-04T22:08:39+0000";
    },
            {
        "can_upload" = 0;
        count = 1;
        "cover_photo" = 318401854907570;
        "created_time" = "2012-05-31T00:00:35+0000";
        description = "Which Friend Stalks You the Most?";
        from =             {
            id = 100002132746588;
            name = "Owner....";
        };
        id = 318401848240904;
        link = "http://www.facebook.com/album.php?fbid=318401848240904&id=100002132746588&aid=73163";
        name = "Which Friend Stalks You the Most?";
        privacy = friends;
        type = normal;
        "updated_time" = "2012-05-31T00:00:36+0000";
    },

等等。问题是,当我尝试解析数据时:

NSLog(@"%@", [result objectForKey:@"name"]);

我明白了null。我认为这种情况正在发生,因为NSDictionary返回的数据不知道name要关注哪个条目。如何解析数据以获取所有专辑的名称?

4

1 回答 1

3

“结果”实际上是一个字典数组,因此遍历数组,然后从数组中的每个元素中获取名称。

for (NSDictionary *anAlbum in [result objectForKey:@"data"]) {
    NSLog(@"%@", [anAlbum objectForKey:@"name"]);
}
于 2012-06-04T23:17:26.027 回答