I got http result in JSON like that
{
"success":true,
"message":[
],
"conversationList":[
"dd184c5a-7eb7-4e98-b588-975853c51b18",
"a3c25d14-d0d5-4e79-928b-1123fe1ba587",
"8c5e2869-43f8-4555-9afd-3b1e679d5ed0",
"843dcbd4-33fc-487f-9971-7fd80ff378c4",
"62dcee64-aeb6-448d-9422-c6b94a22aa02",
"409a8da6-bf32-4dee-923c-213a9971283c"
]
}
I make classes like that:
public class Root
{
public bool success { get; set; }
public List<object> message { get; set; }
public List<string> conversationList { get; set; }
}
and deserialization like this:
var deserializedJson = JsonConvert.DeserializeObject<List<Root>>(result);
Then I got this error:
Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[ConsoleApp9.Root]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path 'success', line 1, position 11.'
I want to use foreach on this and get all conversationList
. How can I resolve this error?
>(result);` to `var deserializedJson = JsonConvert.DeserializeObject(result);`
– Izzy Jan 04 '22 at 14:42