I have a JSON string.
[
{
"target":"FDOL00001",
"datapoints":[
{
"y":72.564,
"x":1523858700
}
]
},
{
"target":"FDOL00001",
"datapoints":[
{
"y":86.366,
"x":1523858700
}
]
},
{
"target":"FDOL00001",
"datapoints":[
{
"y":73.90195818815343,
"x":1523858700
}
]
}
]
I am trying to deserialise it to a collection. But I am getting an error. Can somebody direct me to the right way to fix this?
class datapoint
{
[JsonProperty("x")]
public int x { get; set; }
[JsonProperty("y")]
public decimal y { get; set; }
}
class jsonMapper
{
[JsonProperty("target")]
public string target { get; set; }
[JsonProperty("datapoints")]
public datapoint datapoints { get; set; }
}
I am trying to convert using the following code.
var json = JsonConvert.DeserializeObject<List<jsonMapper>>(objText);
The error I am getting is
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'ISSPortal2.datapoint' because the type requires a JSON object (e.g. {\"name\":\"value\"}) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON object (e.g. {\"name\":\"value\"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.\r\nPath '[0].datapoints', line 1, position 40.
I already checked this . But its not working. What's wrong in my code. Please help me to identify that. Thanks in advance :)