Search code examples
c#facebookdictionaryunity-game-enginefacebook-unity-sdk

Facebook KeyNotFoundException Even Though the Key Exists


So I am using the Facebook Unity API and can't figure out why I get KeyNotFoundException: The given key was not present in the dictionary.

I'm trying to get the last name of the user. First name works fine. I print the Facebook response in the line before which includes the "last_name" key but I still get the exception.

void APICallback(){
    Dictionary<string,string> profile = Util.DeserializeJSONProfile(result.Text);  
    print (result.Text);
    currentUser["Name"] = profile["first_name"];
    currentUser["LastName"] = profile["last_name"];
}

This is the result.Text:

{"id":"XXXXXXX","first_name":"David","last_name":"Richard","friends":{"data":[],"summary":{"total_count":58}}}

Solution

  • It has got to be a bug with Util.DerializeJSONProfile I used SimpleJson to parse result.Text and it works perfectly.