Iphone 从json响应中获取ID的值
我是iPhone应用程序开发新手。我想从Facebook获取用户Id(我的Id)。我怎样才能拿到身份证?控制台中的输出如下所示 谢谢Iphone 从json响应中获取ID的值,iphone,ios,facebook,Iphone,Ios,Facebook,我是iPhone应用程序开发新手。我想从Facebook获取用户Id(我的Id)。我怎样才能拿到身份证?控制台中的输出如下所示 谢谢 - (void)request:(FBRequest *)request didLoad:(id)result { NSLog(@"result is %@",result); } 控制台中的输出如下所示: { email = "kestwalg@gmail.com"; "first_name" = Gaurav; gender = m
- (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";
}
);
}执行
将json响应加载到NSDictionary中:
NSDictionary *myDictionary = [myJsonString JSONValue];
然后从字典里读如下:
NSString *idString = [myDictionary objectForKey:@"id"];
您只需要解析它,幸运的是在iPhone中有很多方法可以轻松地解析它。您可以使用此框架,例如:尝试:
- (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...
}
我的应用程序在NSString*idString=[userDict objectForKey:@“id”行崩溃;控制台打印为-->。-[\uu NSArrayM objectForKey:]:无法识别的选择器发送到应用程序崩溃的行NSString*idString=[userDict objectForKey:@“id”];控制台打印为-->。-[\uu NSArrayM objectForKey:]:无法识别的选择器发送到