2012-07-18 122 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