从json响应中获取ID的值

时间:2012-07-18 12:58:28

标签: iphone ios facebook

我是iPhone App Development的新手。我想从Facebook获得用户ID(我的ID)。我怎样才能获得身份证?控制台中的输出在下面。

感谢

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

}   

控制台输出在这里:

 {   
 email = "kestwalg@gmail.com";
"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";
    }
);

}

3 个答案:

答案 0 :(得分:0)

实施SBJson

将json响应加载到NSDictionary:

NSDictionary *myDictionary = [myJsonString JSONValue];

然后从字典中读取:

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

答案 1 :(得分:0)

你只需要解析它,幸运的是有很多方法可以在iPhone中轻松完成。例如,您可以使用此框架:JSON framework

答案 2 :(得分:0)

试试:

- (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...
}