Unity Community

Register or Sign In:

+ Reply to Thread
Results 1 to 11 of 11

  1. Location
    Santa Fe, New Mexico, USA
    Posts
    860

    json parsing w/ JsonFx

    JsonFx seems to be well recommended for Unity iOS, from a search of forum posts. I just grabbed JsonFx v2.0 and noticed that just using JsonReader and JsonWriter adds System.Xml dependency

    Mono.Security.dll
    System.Xml.dll
    System.dll
    mscorlib.dll
    JsonFx.dll
    Assembly-CSharp.dll

    I was wondering if anyone has tried building a stripped down version of JsonFx 2.0 for use with Unity?

    edit: actually System.Xml.dll is pretty small. I thought it was like 1.2MB. maybe b/c i have build stripping in Pro?


  2. Location
    Santa Fe, New Mexico, USA
    Posts
    860
    NOOOOOOOO. sigh

    ExecutionEngineException: Attempting to JIT compile method 'JsonFx.Serialization.DataReader`1<JsonFx.Model.Mo delTokenType>:Read<System.Collections.Generic.Dict ionary`2<string, object>> (string)' while running with --aot-only.

    at NewBehaviourScript.Start () [0x00000] in <filename unknown>:0


  3. Posts
    6
    I wrote a reply to this a week ago but it apparently didn't post.

    The need for System.Xml is only to support the XML Serialization attributes. If you don't need these, a build would be easy to produce which didn't have that dependency.

    Also there is probably a subset of the JsonFx v2 source that could be built which would be betters suited to this environment. I'm not familiar with Unity enough but there is certainly a lot of flexibility written into JsonFx v2 which is not critical to JSON serialization.


  4. Location
    Santa Fe, New Mexico, USA
    Posts
    860
    The XML dependency is a minor issue, and as you mention is is possible to strip out classes and dependencies.

    The real problem is that for Unity on iOS, it runs in Mono's AOT mode, which is extremely unfriendly toward serialization with Generics, particularly Generics of non-string types. After trying pretty much every serialization method available for C# on iOS, and having all of them throw JIT errors at runtime, I eventually settled on https://github.com/ServiceStack/ServiceStack.Text

    This has the advantage of being extremely fast, working over RPC methods as well as serializing data to PlayerPrefs. But on iOS one must use string types such as Dictionary<string,string> and List<string> for example.


  5. Posts
    6
    I should mention that I'm the developer of JsonFx.

    If I knew the constraints of Mono's AOT mode, I'd be able to produce a build that was more suitable for Unity on iOS. I've seen a lot of people using JsonFx on here but I've never actually made a build specifically for Unity.

    If anyone has any better direction for what needs to change to make it work better on Unity, I'd be happy to try to produce a build for it.


  6. Location
    Santa Fe, New Mexico, USA
    Posts
    860
    mckamey, OK thanks for the info and for JsonFx too! Just to clarify, I think the AOT JIT Errors would arise only running under iOS player. Targeting other Unity platforms such as Win, Mac, webplayer, etc. should not have this issue.


  7. Location
    Zürich, Switzerland
    Posts
    25,088
    Don't use reflection for data parsing (ie json <-> object), parse the Json manually, thats working.
    On AOT, these automagic reflection are severely limited


    as for System.XML: thats standard, most Json / tree parsers you will find in .NET rely on system xml for one or more aspects
    Last edited by dreamora; 03-08-2011 at 05:38 PM.


  8. Posts
    6
    No reflection is needed for deserialization. That is simply reading the JSON text. Reflection is typically used when serializing POCO to JSON.

    JsonFx doesn't rely on System.Xml for anything but the serialization attributes that are pretty commonly used. If you don't use those attributes on your model objects, then you have no need for System.Xml.dll.


  9. Location
    Zürich
    Posts
    44
    Sry for waking up this old thread, but this is still a problem for me

    Has someone a working version of JsonFx, I get it working in editor and Webplayer but not on iOS.
    Beside a lot of Warnings that testing against null does't work and other small stuff, whats not really nice to have so much warning spamm, it's running in Editor, as said above.

    But on iOS i have 2 Problems, stripping with mscorelib is not working. And as dreamora said Object <-> Json parsing is not working.
    But what is working? What is needed to get a Json representation of an Object Array?

    I need to get some Objects with string and number propperties to Json for Device <-> Server communication, something similar to the example here:

    [{"name":"Jon","age":15.2,"someInt":1,"friends":["Fred","Fredine","Fredchen"]},{"name":"Jane","age":18,"someInt":3,"friends":["Franz","Franzie","Franzchen"]}]

    Thx for advice


  10. Posts
    4
    Still doesn't work on the iPhone. :/

    I get loads of these when trying: System.MissingMethodException: Method not found: 'Default constructor not found...ctor() of System.ComponentModel.Int32Converter'.

    If you have an updated/(iOS)working version, it would be..AWESOME.

    Thx


  11. Location
    Santa Fe, New Mexico, USA
    Posts
    860
    I never was able to get JsonFX to work [edit: on Unity iOS]. I would recommend instead, using this small library. No dependencies, open source:

    https://github.com/prime31/UIToolkit...ns/MiniJSON.cs