I have the following JSON I would like to deserialize to a C# model.
{
"$type": "TSNT",
"name": "name",
"ticket": {
"$type": "notifyType",
"$values": [
{
"$type": "test",
"customerName": "atoms"
},
{
"$type": "test2",
"customerName": "atoms2"
}
]
},
"foo": "bar"
}
On Calling the following I get the error: 'Cannot deserialize the current JSON array because the type requires a JSON object to deserialize correctly.'.
Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(ss);
public class Value
{
[JsonProperty("$type")]
public string Type { get; set; }
public string customerName { get; set; }
}
public class Ticket
{
[JsonProperty("$type")]
public string Type { get; set; }
[JsonProperty("$values")]
public List<Value> Values { get; set; }
}
public class Root
{
[JsonProperty("$type")]
public string Type { get; set; }
public string name { get; set; }
public Ticket ticket { get; set; }
public string foo { get; set; }
}
I've tried to decorate the Ticket with [JsonArray] which then throws the error: 'Cannot create and populate list type Ticket. Path 'ticket.$values''
Please could someone explain to me where I'm going wrong?