我有對應於該C#類Deserialise並提取陣列數據表
public class MyClass
{
public string firstString {get; set;}
public string secondString {get; set;}
public List<Person> person{get; set;}
}
public class Person
{
public string age {get; set;}
public string fullName {get; set;}
}
線與錯誤JSON字符串:
List<MyClass> myClassList = JsonConvert.DeserializeObject<List<MyClass>>(JsonString);
目標:目標是從對應於類MyClass的JSON字符串中將Person細節獲取到dataTable中。
如果反序列化已經工作,計劃讓Linq選擇Person並將其放入dataTable中。
而deserialising的JSON字符串MyClass的我得到這個錯誤:
Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.List`1[Project.MyClass]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\r\nTo 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.\r\nPath 'firstString', line 1, position 16."}
感謝編輯@Caesay –