I have a json string that looks like this:
{
"documents": [
{
"name": "20200809/1",
"fields": {
"details": {
"stringValue": "bad"
},
"paid": {
"stringValue": "yes"
}
}
},
{
"name": "20200809/4",
"fields": {
"details": {
"stringValue": "good"
},
"paid": {
"stringValue": "no"
}
}
}
]
}
the strings that matter for me are name, details and paid. When I retrieve the information from the server, it comes like this json.
I'm using JSON .net (JsonConvert) to deserialize but I think I'm doing it wrong. How can I get name and details from this json?
List<object> json = JsonConvert.DeserializeObject<List<object>>(jsonString);
Dictionary<string, object> dict = json[0] as Dictionary<string, object>;
//get name
string name = dict["name"] as string;
It gives me:
Cannot deserialize the current JSON object because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
[and an object starts with{- guess what you have hereDictionary<string, List<object>>instead?JObjectas answer and I'll gladly accept it. Just solved the problem using it :) Thanks.