coder4life22
coder4life22

Reputation: 199

Json From Facebook and Unity

I have a json returned from the Facebook SDK in unity that looks like this:

{"name":"Name_of_person", "id":"989988988"}

I've taken a look at the raw JSON and this is what it looks like after I submit a query for that information via the Graph API.

So far I am trying to deserialize the json as such:

void DealWithProfileInfo(IGraphResult result){


    Dictionary<string,string> profile = JSON.Deserialize (result.RawResult) as Dictionary<string,string>;

    scoresText.text = profile ["first_name"];
    idText.text = profile["id"];

DealWithProfileInfo being my callback method from the FB.API call.

for some reason none of the information gets displayed and I am not sure why.

Am I missing something? Or maybe I am parsing the data wrong?

Upvotes: 1

Views: 967

Answers (1)

Hamza Hasan
Hamza Hasan

Reputation: 1359

Actually it is my personal experience that whenever I mess up with Facebook SDK or any other JSON in Unity3d, then what ever the hierarchy of JSON would be, it always returns Dictionary<string,object>. So developer have to come through that stairs

So in your case you should declare and cast to Dictionary<string,object> instead of Dictionary<string,string> then convert that object to string.

Upvotes: 1

Related Questions