简体   繁体   中英

get the value of ID from json response

I am new in iPhone App Development. I wants to get User Id (my id) from Facebook. How can I get the 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 .

Load json response into 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. You can use this framework for instance: JSON framework

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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