0

I have an issue, I cannot figure out how to deserialize this JSON. I've tried a number of things, from Dictionary, to Lists. I know the item I'm after is a dataset and I tried that also, nothing works. This is the JSON structure

{
"myRoot": {
    "myList": [
        {
            "data1": "somedata",
            "data2": "somedata"
        },
        {
            "data1": "somedata",
            "data2": "somedata"
        },
        {
            "data1": "somedata",
            "data2": "somedata"
        },
        {
            "data1": "somedata",
            "data2": "somedata"
        },
    ]
   }
}

These are the classes that are not working

private class WTH
{
    [JsonProperty("myList")]
    public List<Codes> mystuff { get; set; }
}
private class Codes
{
    [JsonProperty("data2")]
    public string data2{ get; set; }
}

My deserialization that either blows up, or ends up null.

WTH summary = JsonConvert.DeserializeObject<WTH>(response.Content);

1 Answer 1

1

You need another wrapper class around that with a myRoot property. For example:

public class Rootobject
{
    [JsonProperty("myRoot")]
    public WTH WTH{ get; set; }
}

public class WTH
{
    [JsonProperty("myList")]
    public List<Codes> mystuff { get; set; }
}

public class Codes
{
    public string data1 { get; set; }
    public string data2 { get; set; }
}

And deserialise like this:

var summary = JsonConvert.DeserializeObject<Rootobject>(response.Content);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.