Simple JSON parsing problem

Hi guys, I’m fairly new to JSON and I’m getting some dificulties parsing this structure. To my eyes everything seems fime but I am unable to correctly parse it. Can anyone spot me what I’m doing wrong please?

{
    "ItemDatas":
    [
        {
            "Name": "carton of ice cream",
            "Description": "A carton of ice cream.",
            "Stat": 94,
            "IconIndex": 29
        },
        {
            "Name": "bananas",
            "Description": "A bananas.",
            "Stat": 53,
            "IconIndex": 9
        }
    ]
}

class InventoryItemDatas
    {
        public InventoryItemData[] ItemDatas;
    }

class InventoryItemData
    {
        public int IconIndex;
        public string Name;
        public string Description;
        public int Stat;
    }



var inventoryItemDatas = JsonUtility.FromJson<InventoryItemDatas>(StringJSON);

The object inventoryItemDatas is null after I attempt the deserialization

Problems with Unity “tiny lite” built-in JSON:

In general I highly suggest staying away from Unity’s JSON “tiny lite” package. It’s really not very capable at all and will silently fail on very common data structures, such as Dictionaries and Hashes and ALL properties.

Instead grab Newtonsoft JSON .NET off the asset store for free, or else install it from the Unity Package Manager (Window → Package Manager).

https://forum.unity.com/threads/jso…-not-working-as-expected.722783/#post-4824743

Also, always be sure to leverage sites like:

https://csharp2json.io

PS: for folks howling about how NewtonSoft JSON .NET will “add too much size” to your game, JSON .NET is like 307k in size, and it has the important advantage that it actually works the way you expect a JSON serializer to work in the year 2021.

In addition to @Kurt-Dekker 's suggestions, I could add JSON Object asset (free on the asset store), which I find the most reliable and simple among the JSON libraries for Unity. We have been using this asset on a published mobile project (iOS and Android) for about a year now and haven’t faced any serious problems so far.

much apreciated guys! With just a single line of code changed (switching from unity json deserializer to newtonson), everything works beautifully!

Hi, I’d like to add that Unity’s JsonUtility should work with your example if you add the [System.Serializable] attribute to InventoryItemData. InventoryItemDatas doesn’t need to have it, but it’s good practice to put the SerializableAttribute in there anyway. Depending on your case, JsonUtility might give you better performance.