Search code examples
c#jsonjson-deserialization

Deserialize JSON (Json.NET)


I need a little help with json deserialization. It's the first time I'm using Json, so I have just a little knowledge about it.

I get the following string using a webclient:

[{"name": "somename", "data": [[72, 1504601220], [null, 1504601280], ..., [125, 1504605840]]}]

and tried to serialize it with

JsonConvert.DeserializeObject<TestObject>(jsonstring)

My class looks like this:

public class TestObject
{
    [JsonProperty(PropertyName = "name")]
    public string TargetName { get; set; }

    [JsonProperty(PropertyName = "data"]
    public List<?????> DataPoints {get; set;}
}

How do I need to design my class to get the data values in some kind of collection so each entry contains the two values inside a bracket?

Thx for your patience and help!


Solution

  • Your data is a list of arrays containing nullable integers (by the looks of it)

    [JsonProperty(PropertyName = "data"]
    public List<int?[]> DataPoints {get; set;}