Unity C#, JSON deserialization suddenly stopped working

42 Views Asked by At

My JSON deserialization in a Unity project suddenly stopped working with some of the input. I'm using JsonFX.

JSON:

{"CloudsRoot": [
    {
        "id": "94",
        "campaign_id": "32",
        "text": "CustomImage",
        "bubble_num": "-1",
        "img1_name": "59e72a6f1a341",
        "img2_name": "59e72a6f1b885"
    },
    {
        "id": "95",
        "campaign_id": "32",
        "text": "Default Image",
        "bubble_num": "4",
        "img1_name": "4",
        "img2_name": "4"
    }]}

Data Model:

using System.Collections.Generic;

public class CloudsRoot {
    public List<Clouds> Clouds{ get; set; }

}

public class Clouds {
      public string id { get; set; }
      public string campaign_id{ get; set; }
      public string text { get; set; }
      public string bubble_num { get; set; }
      public string img1_name { get; set; }
      public string img2_name { get; set; }

}

Deserialization method:

public CloudsRoot Deserialize(jsonString) {
    CloudsRoot responseObject = JsonReader.Deserialize<CloudsRoot>(jsonString);
    return responseObject;
}

What's returned is a CloudsRoot object with an empty List inside. I tried serializing a single Cloud object and it works. What's worse is that I have several different JSON snippets being deserialized using the same method and data model structure (only variable names differ) and they all work.

I'm confident the data model is proper, the JSON is proper and that there are no typos. I tried rewriting the code inside a fresh unity project and the result is the same. Evidence suggests that the JSON snippet is somehow faulty, but I haven't been able to find the problem for several hours now.

I'll greatly appreciate any input.

EDIT: Please do not close this question, it is not a duplicate. I tried with JsonHelper and I'm still getting an empty array as a result. I tried all the possible solutions from the troubleshooting section, too.

0

There are 0 best solutions below