我正在尝试按顺序将 Json 对象反序列化为动态列表,所以我有:
杰森:
string json = "{'elements':[
{'EntityA':[
{'name ':'Jhon'}
],
'EntityB':[
{'title' : 'car'}
],
'EntityB':[
{'title':'aaa'}
],
'EntityA':[
{'name' : 'Alice'}
]]}";
.NET 类基类:
public interface EntitysInterface{}
public class EntityA: EntitysInterface
{
public string name { get; set; }
}
public class EntityB: EntitysInterface
{
public string title { get; set; }
}
public class Entitys
{
public List<EntitysInterface> elements { get; set; } //EntityA, EntityB,...
public Entitys()
{
}
}
我的反序列化对象困难:
Entitys listFinaly = JsonConvert.DeserializeObject<Entitys>(json);
异常“类型是接口或抽象类,无法实例化。:(”