{
Items: [
{
"title": "Object1",
"preview": {
"2048": "preview_9212.jpg",
"1024": "preview_6693.jpg",
}
},
{
"title": "Object2",
"preview": {
"2048": "preview_9888.jpg",
"1024": "preview_6890.jpg",
}
},
{
"title": "Object3",
"preview": {
"2048": "preview_9822.jpg",
"1024": "preview_6848.jpg",
}
}
]
}
I usually deserialise like this:
[Serializable]
public class JsonParser
{
public string title;
public List<Preview> preview;
}
[Serializable]
class Preview
{
public string 2048;
}
But since 2048 is an Integer is not possible to use this way. I tried to deserialize the JSON to get preview like these:
public class Preview
{
[JsonProperty("2048")]
public string imageNumber { get; set; }
}
var user = JsonConvert.DeserializeObject<Preview>(jsonValue);
or
var json = JObject.Parse(jsonValue);
var preview = json["preview"].ToObject<Dictionary<string, string>>();
foreach (var entry in preview)
{
Debug.Log(entry.Key);
Debug.Log(entry.Value);
}
I got: NullReferenceException: Object reference not set to an instance of an object.
I also tried Deserializing JSON that has an int as a key in C# but again NullReferenceException;
Thanks for any help!
Items), and will be difficult to deserialize because of differing property names (two of the objects have"title", one has"type"). Please edit your title, as there are no integer keys; there are numeric string keys. Similar problem, different description.