I am trying to deserialize a JSON http response, but I keep getting the error "object reference not set to an instance of an object".
I know this is a commonly asked question, but nothing I found about the error has helped me. I think I am missing something very basic.
The JSON response I'm getting looks something like this:
{
"value": [
{
"createdDateTime": "2020-03-14T12:25:54Z",
"id": "W2RQ6DOBCJUXWGR35DLKP7UI6IN",
"name": "somename",
"size": 200230,
},
{
"createdDateTime": "2020-03-24T08:25:03Z",
"id": "Q6DOBCJUXWFIGR35DLWERKP7UI6IN",
"name": "somename",
"size": 200230,
},
...
]
}
I already managed to deserialize properties that only occur once in the response. However, this time I need the properties "id" and "name" back. Here is how I tried that:
public class Value
{
public string Name { get; set; }
public string Id { get; set; }
public Value[] Children { get; set; }
}
public class RootObject
{
public Value[] RespValues { get; set; }
}
var objJSON = JObject.Parse(jsonresponse);
var objResponse = objJSON["Response"].ToString();
RootObject categoryTree = JsonConvert.DeserializeObject<RootObject>(objResponse);
I tried a few different approaches so far, but every single one caused the error. I'm not really sure what I'm doing wrong.