简体   繁体   English

从json响应中获取ID的值

[英]get the value of ID from json response

I am new in iPhone App Development. 我是iPhone App开发的新手。 I wants to get User Id (my id) from Facebook. 我想从Facebook获取用户ID(我的ID)。 How can I get the ID? 我如何获得ID? the output in console is below. 控制台中的输出如下。

thanks 谢谢

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

}   

Output in console is here: 控制台中的输出在这里:

 {   
 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";
    }
);

} }

Implement SBJson . 实施SBJson

Load json response into NSDictionary: 将json响应加载到NSDictionary中:

NSDictionary *myDictionary = [myJsonString JSONValue];

Then read from dictionary like: 然后像这样从字典中读取:

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

You just need to parse it, luckily there are a number of ways to do so easily in iPhone. 您只需要解析它,幸运的是,有多种方法可以在iPhone中轻松地做到这一点。 You can use this framework for instance: JSON framework 您可以使用此框架作为示例: JSON框架

Try that: 试试看:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM