Hi,
I searched and found that JsonMapper is not compatible with IOS.
I created my own functions to find the needed Values.
first of all copy the LitJson.dll file from Paul Tondeur web site, (see links below) to your asset folder
import LitJson;
function GetVal (jsonString:String,property:String):String
{
var reader : JsonReader = new JsonReader(jsonString);
while (reader.Read())
{
if (reader.Token.ToString() == "PropertyName" reader.Value.ToString() == property )
{
reader.Read();
if (reader.Token.ToString() == "Double" || reader.Token.ToString() == "Int" || reader.Token.ToString() == "String")
return reader.Value.ToString();
}
}
}
function GetArray(jsonString:String,property:String):Array
{
var array = new Array ();
array.Clear();
var reader : JsonReader = new JsonReader(jsonString);
while (reader.Read())
{
if (reader.Token.ToString() == "PropertyName" reader.Value.ToString() == property )
{
reader.Read();
if (reader.Token.ToString() == "ArrayStart")
{
while (reader.Token.ToString() != "ArrayEnd")
{
reader.Read();
if (reader.Token.ToString() == "Double" || reader.Token.ToString() == "Int" || reader.Token.ToString() == "String")
{
array.Push (reader.Value.ToString());
}
}
}
return array;
}
}
}
And these could be used to find the needed values.
var text : String;
var resultCount = GetVal (text, "resultCount");
Debug.Log (resultCount);
//and with an array or value :
var Screenshots = new Array ()
Screenshots.Clear();
Screenshots = GetArray (text, "screenshotUrls");
for (var i =0; i< Screenshot.length; i++)
Debug.Log (Screenshot[i]);
Hope it would help people stuck with this JsonMapper issue
Thanks to people who shared, found the solution in this thread :
and thanks to Paul Tondeur for sharing his LitJson.dll file and his tutorial :
Did you ever figure out why it doesn’t work on ios? I am having the exact same problem, but I’d really like to use the JsonMapper and I can’t find why it shouldn’t work on ios as it doesn’t do anything that would be forbidden on ios.
There seem to be two ways to use this library. The first one uses the ToObject() method and will create a hierachy of JsonData objects that represent the original json using untyped Dictionaries Lists and arrays. The second approach allows you to use the generic ToObject method. To use this you would do something like the following:
public class MyDataObject {
public string name;
public int number;
}
This would serialize the object to a json string and then deserialize it to a new object. This works with any kind of data, so if you get some data as a respnse from a server you would just create a class containing the respective fields and then you can use the ToObject method to create an object of that type from a json string.
thank you for the reply… unfortunately I’m still stuck:(
Do i still need to implement the francksitbon code if I only want to write the file to an array and just display the text. (json contains all text).
public string[ ] jsonTeamsSelected = new string[ ];
public string[ ] jsonDefSelected = new string[ ];
Oh, I misunderstood.
But I debugged the problem and now LitJson works fine on my iOS, with non-generic ToObject(). The problem was in line 532 of JsonMapper.cs.
This makes ReadValue() called again and again before assignment and consume all the members of currently parsing object. I suppose this is an AOT compiler bug or something, but don’t know exactly. Anyway separating call to ReadValue() and assignment and prevent optimizer from merging them again fixed the problem.
In my case the problem was not an exception, but corrupt resulting data, so I don’t know if this workaround will save everyone having similar issues.