- Home /
Parsing JsonData throws error when value is null, what to do?
Using LitJson and the Facebook graph api inside a Unity webplayer build is giving me problems with data parsing.
Data:
{"data":[{"name":"Red Green","uid":111111111,"wall_count":null,"pic":"http:\/\/profile.ak.fbcdn.net\/hprofile-ak-snc4\/11111_111111111_2289168_s.jpg"}]}
Offender:
JsonData myListing = _return; //the Json data above
for(int i = 0; i<myListing["data"].Count; i++)
{
holdText += i.ToString() + ": " + myListing["data"][i]["name"] + " ";
holdText += myListing["data"][i]["wall_count"].ToString() + " ";
holdText += myListing["data"][i]["pic"] + "\n";
}
Any line of code that references ["wall_count"] will result in an error if the value is null. The problem is compounded because the code runs in the web player plug-in that does not provide error information.
So, if I can expect "wall_count" values to be null, how can I check without throwing the error?
myListing["data"][i].Count is 4, so there are 4 objects there (name,uid,wall_count,pic), but trying to access the wall_count one will fail.
Your answer
Follow this Question
Related Questions
How to create ,store and append data to json from unity using unity webplayer ? 0 Answers
Facbook Authentication token 0 Answers
Application.ExternalCall Issue 0 Answers
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers
WebGL Redirect 0 Answers