Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

JsonUtility news (fix broken stuff) ?

Discussion in '5.4 Beta' started by bdovaz, Dec 24, 2015.

  1. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,042
    We need:

    - Be able to deserialize null objects, having:

    {"type": "image","location": null }

    And "location" being a "Location" class outputs in the console "name == NULL UnityEngine.JsonUtility:FromJson(String)"

    - Be able to deserialize arrays:

    {"type": "image","tags": [] }

    Deserializing tags (string[] tags) outputs in the console "Unexpected node type. UnityEngine.JsonUtility:FromJson(String)"


    I still don't understand how Unity releases broken features like this and they leave it as is without any news when are they going to fix all of this.
     
  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    Hi,

    As mentioned in the manual,

    Null is not supported by the standard Unity serializer, so it is not supported by JsonUtility either. That said, it should not produce the error message you are seeing, I will look into that.

    Regarding arrays - can you show the class or structure you are using for deserialisation of the JSON in your second example? I'm not aware of any bugs relating to this behaviour, so either there's something wrong with what you are trying to do, or you found something that I don't know about.
     
  3. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    I've just tested the 'null' situation and I cannot reproduce the error message you mentioned. Can you also show me the classes/structures you are using for deserialisation in that case?
     
  4. tealm

    tealm

    Joined:
    Feb 4, 2014
    Posts:
    108
    I think the original poster is talking about multidimensional arrays?
    Ie: the following test outputs {}

    Code (CSharp):
    1. int[,] b = {{0, 1}, {2, 3}, {4, 5}, {6, 7}, {8, 9}};
    2. Debug.Log(JsonUtility.ToJson(b));

    I would really like to use JsonUtility as I've noticed great performance gains in parsing large JSON files vs 3rd party libraries like JSON .NET and LitJSON, but as it is now there's really no point in using is cause of all the missing features.

    *EDIT* if you search for JsonUtility in Unity Answers you can see that alot of users are having problems trying to use this new native parser, cause it doesn't support arrays and collections. You should at least specify the current limitations in the docs.
    http://answers.unity3d.com/search.html?f=&type=question&redirect=search/search&sort=relevance&q=JsonUtility
     
    Last edited: Jan 11, 2016
  5. fermmmm

    fermmmm

    Joined:
    Oct 18, 2013
    Posts:
    129
    I've made a post about this with code you can run to reproduce the issue. It seems 2D arrays are not supported, this is probably a bug and not a missing feature since even the worst Json decoder out there supports 2D arrays:
    http://forum.unity3d.com/threads/js...-json-and-also-from-json.387884/#post-2524356