Deserialize list of objects in C#
Solution 1:
You have to use JsonConvert.Deserialize
method.
Your json
string is wrapped within square brackets ([])
, hence it is interpreted as array. Therefore, you need to deserialize
it to type
collection of one class
, for example let's call it MyClass
.
public class MyClass
{
public int matId { get; set; }
public int value { get; set; }
}
Here is Deserialize
method.
var results=JsonConvert.DeserializeObject<List<MyClass>>(json);
Solution 2:
Backslashes represent serialized object. You need to deserialize your List object. You can try using Generics:
public List<T> Deserialize<T>(string path)
{
return JsonConvert.DeserializeObject<List<T>>(path);
}