I trie to check if the returned value from objectForKey is not NULL
if([[fbResult objectForKey:@"current_location"]objectForKey:@"country"])
formViewController.country=[[fbResult objectForKey:@"current_location"]objectForKey:@"country"];
But i have an error on the first line
UPDATE
fbResult is a JSON string,if the user has puted his city and his country in facebook it look like :
"birthday_date" = "07/*****9";
"contact_email" = "***mehdi@hotmail.fr";
"current_location" = {
city = Tunis;
country = Tunisia;
id = 11166369***;
name = "Tunis, Tunisia";
state = Qabis;
zip = "";
};
locale = "fr_FR";
name = "Mehdi ****el";
pic = "https://fbcdn-profile-a.akamaihd.net/hprofile-********_s.jpg";
sex = male;
uid = 530****;
}
and if the user did not put his country and city it look like :
{ "birthday_date" = "02/*3/19**";
"contact_email" = "kev**kevin@gmail.com";
"current_location" = "<null>";
locale = "fr_FR";
name = "Aude ***";
pic = "http://profile.ak.fbcdn.net/hprofile-ak-snc4/4***2_**8_1112_s.jpg";
sex = female;
uid = 11***04*;
}
error is
-[NSObject(NSObject) doesNotRecognizeSelector:] + 96
Checking for existence of an object within a dictionary that is nested in another dictionary is not going to catch all occurrences of bad data.
To make your code more solid
If the current_location is supposed to be a dictionary you can swap out
id currentLocationwithNSDictionary * currentLocationfrom your update, your current_location can potentially be an instance of
NSNullyou can check against that with
[yourObject class] != [NSNull class]