检查Facebook请求结果

时间:2011-08-17 23:08:10

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

我想知道在iOS设备上请求Facebook Graph API时如何检查结果的结构。例如:

[facebook requestWithGraphPath:@"me/friends" andDelegate:self]; 

谢谢:)

1 个答案:

答案 0 :(得分:0)

您需要检查对象的类型(可能是NSArray或NSDictionary),然后相应地迭代

NSString *key, *val;
NSEnumerator myenum;      
if ([result isKindOfClass:[NSDictionary class]]) {
        for (key in result) {
            myenum = [result objectEnumerator];
            while (val = [myenum nextObject]) {
                if ([val isKindOfClass:[NSArray class]]) {
                for (id entry in (NSArray *)val) {

                    if ([entry isKindOfClass:[NSDictionary class]]) {
                        NSString * theid = [(NSDictionary *) entry objectForKey:@"id"];
                        NSString *thename = [(NSDictionary *)entry objectForKey:@"name"];
                        // do your stuff here
                    }
           }
        }