I have JSON file like:
[
12,
[
{
"id": "131",
"name": "Cate"
},
{
"id": "132",
"name": "Mike"
}
],
"Result OK"
]
And Code:
private static void Main(string[] args)
{
using (var r = new StreamReader(@"C:\Path\data1.json"))
{
var json = r.ReadToEnd();
try
{
var items = JsonConvert.DeserializeObject<JsonBody>(json);
Console.WriteLine(items);
}
catch (JsonSerializationException ex)
{
Console.WriteLine(ex);
}
}
}
public class JsonBody
{
public int someint;
public List<Dictionary<string, Item>> item;
public string somestring;
}
public class Item
{
[JsonProperty("id")] public string id;
[JsonProperty("name")] public string name;
}
Error:Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Json_parser.Parse2+JsonBody' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
What should be rewritten in the code to avoid this error. How do I parse this JSON correctly? I need to get all items from the Item class.