Im with problem deserialize Json with newtonsoft json.
I have a class
[Serializable]
public class ValueAdd
{
[JsonProperty(PropertyName = "@id")]
public string Description { get; set; }
[JsonProperty(PropertyName = "@description")]
public string Id { get; set; }
}
[Serializable]
public class ValueAdds
{
public List<ValueAdd> ValueAdd { get; set; }
[JsonProperty(PropertyName = "@size")]
public string Size { get; set; }
}
And the API returning the stupid two things of format: One i can serialize correct:
"ValueAdds":
{
"@size": "3",
"ValueAdd":
[
{
"@id": "2103",
"description": "some property"
},
{
"@id": "2192",
"description": "some property"
},
{
"@id": "2196",
"description": "some property"
}
]
}
But when they return one property it didnt return a list.. only return on this way:
"ValueAdds":
{
"@size": "1",
"ValueAdd":
{
"@id": "2103",
"description": "some property"
}
}
Causing me a parser error with
JsonConvert.DeserializeObject<ValueAdds>(_response);
A first chance exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll
Additional information: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[myproperty]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
My question is, is there anyway to fix it?? I cant change the api response, need change from my side trying to parse if there is a list or not..