JsonUtility news (fix broken stuff) ?

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.

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.

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?

I think the original poster is talking about multidimensional arrays?
Ie: the following test outputs {}

int[,] b = {{0, 1}, {2, 3}, {4, 5}, {6, 7}, {8, 9}};
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

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/jsonutility-fails-to-convert-2d-arrays-to-json-and-also-from-json.387884/#post-2524356