I’m using LITJson on iOS to take JSON output from a server and fill out a game with the content i receive.
The code works the first time around, but on second execution fails, and it looks like its a known bug with the JsonMapper.ToObject($string) command specifically.
The JSON file i have has an array, with multiple items in it, so whichever JSON plugin/script is out there that works with iOS would need to support nested data (most should). I’ve seen Boomlagoons, MiniJSON and JsonFX, but i figured i’d ask here for users experiences with these 3, and possibly others, on iOS and Android.
The JSON i’m trying to parse looks like this:
{
"shot":[
{
"id":"2",
"version":"1",
"shot_type":"_3D",
"disp_type":"main",
"sort_order":"150",
"display_name":"Dragon",
"display_info":"Fiery and ready to fly!",
"web_store":"https://URL/id2_dragon-01_store.unity3d",
"web_store_version":"1",
"web_content":"https://URL/id2_dragon-01_shot.unity3d",
"web_content_version":"1",
"ios_store":"https://URL/iphone_id2_dragon-01_store.unity3d",
"ios_store_version":"1",
"ios_content":"https://URL/iphone_id2_dragon-01_shot.unity3d",
"ios_content_version":"1",
"android_store":"https://URL/android_id2_dragon-01_store.unity3d",
"android_store_version":"1",
"android_content":"https://URL/android_id2_dragon-01_shot.unity3d",
"android_content_version":"1",
"preview":"https://URL/id2_dragon-01_preview.ogv",
"result":""
},
{
"id":"3",
"version":"1",
"shot_type":"_3D",
"disp_type":"main",
"sort_order":"200",
"display_name":"T-Rex",
"display_info":"King of the Dinosaurs!",
"web_store":"https://URL/id3_trex-01_store.unity3d",
"web_store_version":"1",
"web_content":"https://URL/id3_trex-01_shot.unity3d",
"web_content_version":"1",
"ios_store":"https://URL/iphone_id3_trex-01_store.unity3d",
"ios_store_version":"1",
"ios_content":"https://URL/Trex-01/iphone_id3_trex-01_shot.unity3d",
"ios_content_version":"1",
"android_store":"https://URL/Trex-01/android_id3_trex-01_store.unity3d",
"android_store_version":"1",
"android_content":"https://URL/Trex-01/android_id3_trex-01_shot.unity3d",
"android_content_version":"1",
"preview":"https://URL/id3_trex-01_preview.ogv",
"result":""
}
]
}
LITJson made it quite easy to access the children of the array as so:
for(int i = 0; i<jsonShots["shot"].Count; i++)
{
shot = new ShotItem();
shot.id = Convert.ToInt16(jsonShots["shot"][i]["id"].ToString());
shot.version = Convert.ToInt16(jsonShots["shot"][i]["version"].ToString());
shot.shot_type = jsonShots["shot"][i]["shot_type"].ToString();
shot.disp_type = jsonShots["shot"][i]["disp_type"].ToString();
shot.sort_order = Convert.ToInt16(jsonShots["shot"][i]["sort_order"].ToString());
shot.display_name = jsonShots["shot"][i]["display_name"].ToString();
shot.display_info = jsonShots["shot"][i]["display_info"].ToString();
shot.preview = jsonShots["shot"][i]["preview"].ToString();
shot.result = jsonShots["shot"][i]["result"].ToString();
}
Super simple, and easy to cast the JSON data directly to C# variables.
Do any of the above (or other) Json scripts do something similar?
I’m also open to changing the JSON structure to get back a different result if the above isn’t formatted in a JSON compliant manner as i’m fairly new to JSON as a format.
Thanks in advance for any help/information.
Nathaniel Hunter
SuperTales Inc.
www.supertalesinc.com