繁体   English   中英

从json响应中获取ID的值

[英]get the value of ID from json response

我是iPhone App开发的新手。 我想从Facebook获取用户ID(我的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";
    }
);

}

实施SBJson

将json响应加载到NSDictionary中:

NSDictionary *myDictionary = [myJsonString JSONValue];

然后像这样从字典中读取:

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

您只需要解析它,幸运的是,有多种方法可以在iPhone中轻松地做到这一点。 您可以使用此框架作为示例: JSON框架

试试看:

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