Dictionary support (or workaround) for JsonUtility (test case included)

For example, is there any way to parse this structure? (NOTE: Title field being dynamic and not a 3 fixed value structure)

{
    "id": 1,
    "title": {
        "es": "1",
        "en": "2",
        "fr": "3"
    }
}
public class Test {
    public int id;
    public Dictionary<string, string> title;
}

https://feedback.unity3d.com/suggestions/support-conversion-of-json-string-into-a-dictionary

First off, not particularly relevant to 5.4 beta, but I’ll still answer.

From our docs page: Unity - Manual: JSON Serialization

and later on

Trade-offs were made for speed, less allocations, and also clean integration with our serialization system. There’s other work we have to do first to get dictionary support in.

1 Like

You should approach FullInspector/FullSerializer developer. This guy has made so much work on Unity serialization and he is able to serialiaze pretty much everything in json (dictionary, interface, inheritance, generics …).

Unity must hire this guy and give him the chance to improve the core engine :slight_smile:

Like it was said above and was said elsewhere they want to first have as efficient and light weighted support they can at start and not to bloat it with every feature a man can think of. It’s not really lack of skills or anything. There are already a lot of full feature set libs out there for free and paid.

We know that but many many people will use it to consume third parties web services where you can’t have control of the JSON output and it’s really common to have “Dictionary” like random structures.

So right now, Unity JSONUtility is useless.

1 Like

Im afraid my line of thinking goes in the same direction. JsonUtility seems like a mere anecdotic class. Currently the feature set can only work with an object. From and to Json, only supports an object.

If you have a Json string with an array of objects, wont work. Let’s not even mention nested arrays. And json is basically keys value pairs, but deserializing to a dictionary seems to be asking for “slow bloatware”.

I was exited about replacing third party dependencies, but resulted tough to find that my very basic needs, deserializing an array of objects, was too much to handle for the Unity API.

I highly recommend fastJSON: https://fastjson.codeplex.com/

Open source, very lightweight, superfast, can handle everything you throw at it, comes with a .NET 2.0-specific version that works with Unity.

Yes and there is also Json .NET on Asset Store but I want to use the Unity implementation so I don’t depend on third party libraries.

1 Like

Good luck with that :smile:

Everything in Unity is made to be extended and improved. It’s part of what makes it shines. Trust me, you don’t want to depend entirely on one company to create your game, especially Unity. We have fast turnarounds when it comes to fixing bugs with store packages, but with Unity, fixing one big bug can take several months.

1 Like