2012-07-18 166 views
0

我是iPhone应用开发中的新手。我想从Facebook获取用户ID(我的ID)。我如何获得ID?控制台中的输出如下。从json响应中获取ID的值

感谢

- (void)request:(FBRequest *)request didLoad:(id)result 
{ 
    NSLog(@"result is %@",result); 

} 

输出控制台是在这里:

{ 
email = "[email protected]"; 
"first_name" = Gaurav; 
gender = male; 
hometown =  { 
    id = 1231243212321; 
    name = Haridwar; 
}; 
id = 1213213231231; 
"last_name" = K; 
link = "http://www.facebook.com/kestwal.75"; 
locale = "en_US"; 
location =  { 
    id = 123123123123; 
    name = "New Delhi, India"; 
}; 
name = "Gaurav Kestwal"; 
timezone = "5.5"; 
"updated_time" = "2012-07-10T06:46:25+0000"; 
username = "gaur.75"; 
verified = 1; 
work =  (
      { 
     employer =    { 
      id = 12312312312; 
      name = "NKAPs Intellects Noida"; 
     }; 
     position =    { 
      id = 213123123213; 
      name = "iPhone Application Developer"; 
     }; 
     "start_date" = "0000-00"; 
    } 
); 

}

回答

0

实现SBJson

加载JSON响应到的NSDictionary:

​​

从字典像然后阅读:

NSString *idString = [myDictionary objectForKey:@"id"]; 
0

你只需要解析它,幸运的是有没有iPhone那么容易很多方法可以做到。您可以使用例如这个框架:JSON framework

+0

我的应用程序崩溃[UserDict中objectForKey:@ “ID”];控制台打印是 - > .- [__ NSArrayM objectForKey:]:无法识别的选择器发送到 – 2012-07-18 13:45:04

0

尝试是:上线的NSString * idString =

- (void)request:(FBRequest *)request didLoad:(id)result { 
    NSString *jsonString = [NSString stringWithString:[result JSONRepresentation]]; 
    NSDictionary *userDict = [jsonString JSONValue]; 
    // do something with the values in the dictionary... 
} 
+0

我的应用程序崩溃在线NSString * idString = [userDict objectForKey:@“id”];控制台打印是 - > .- [__ NSArrayM objectForKey:]:无法识别的选择器发送到 – 2012-07-18 13:43:40

+0

Sry。我已经更新了答案。 – borisdiakur 2012-07-18 13:54:00