如何解析facebook喜欢json的回复?

时间:2015-04-13 09:06:43

标签: ios objective-c facebook-graph-api

我设法让用户喜欢使用此代码:

[FBRequestConnection startWithGraphPath:@"/me/likes"
                             parameters:nil
                             HTTPMethod:@"GET"
                      completionHandler:^(
                                          FBRequestConnection *connection,
                                          id result,
                                          NSError *error
                                          ) {
                          /* handle the result */
                          NSLog(@"User interests data: %@",result);
                          self.likesTextView.text = [NSString stringWithFormat:@"User interests data: %@",result];

}];

这是日志:

User interests data: {

data =     (

            {

        category = Company;

        "created_time" = "2015-04-09T11:31:13+0000";

        id = 403422586500762;

        name = "Sky3888 iOS & Android - Officially Agent";

    },

            {

        category = "Games/toys";

        "created_time" = "2015-04-09T11:30:57+0000";

        id = 1575053229378162;

        name = i12win;

    },

            {

        category = "Shopping/retail";

        "created_time" = "2015-04-07T04:44:09+0000";

        id = 273182176129865;

        name = Tinkerbelle;

    }
 );

但是,我如何获取并显示UILabel中的“名称”和“类别”字段?

2 个答案:

答案 0 :(得分:1)

您可以执行以下操作

NSDictionary *responseDict=(NSDictionary *)result;
    NSArray *mainArray=[responseDict objectForKey:@"data"];

    for (NSDictionary *dict in mainArray) {
        nameLabel.text=[dict valueForKey:@"name"];
        catLabel.text=[dict valueForKey:@"category"];
    }

希望它可以帮助你......!

答案 1 :(得分:0)

制作NSArray的{​​{1}},然后循环浏览resultobjectForKey中执行category功能的对象,以提取您的数据想。

这里有一个类似的问题: NSMutableArray losing all objects

您应该可以使用该代码并将结果复制到UILabel中。