- Home /
Parsing a JSON response
Hello, I'm trying to handle a JSON response from a facebook plugin. here is the reponse:
{
"data": [
{
"user": {
"name": "Test Name",
"id": "123456789"
},
"score": 20920,
"application": {
"name": "Test Game",
"namespace": "TestGame",
"id": "123456678899087"
}
},
{
"user": {
"name": "Test Name",
"id": "123456789"
},
"score": 17340,
"application": {
"name": "Test Game",
"namespace": "TestGame",
"id": "123456678899087"
}
}
]
}
I was able to handle similar facebook response (me/friends) with this code:
try {
JsonData friends = JsonMapper.ToObject(FacebookUnityPlugin.response);
Debug.Log(friends["data"][0]["id"]);
friendlist = "";
for (int i = 0; i < 5; i++) {//First 5 friends
friendlist = friendlist + System.Environment.NewLine + friends["data"][i]["name"];
}
} catch (System.Exception ex){
Debug.Log(ex.Message);
}
But in this case this code doesn't work because I have nested data ..
Any help please ?
Comment
Best Answer
Answer by Luca91 · Jun 14, 2013 at 03:39 PM
Fixed using:
for(int k=0;k<friends["data"].Count;k++)
friendlist = friendlist + System.Environment.NewLine + friends["data"][k]["user"]["name"] + " " + friends["data"][k]["score"];
Thanks anyway :)