Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# JSON.NET按顺序将对象从数组反序列化到列表_C#_Json_Json.net - Fatal编程技术网

C# JSON.NET按顺序将对象从数组反序列化到列表

C# JSON.NET按顺序将对象从数组反序列化到列表,c#,json,json.net,C#,Json,Json.net,我试图按顺序将Json对象反序列化为动态列表,因此: Json: .NET类基类: public interface EntitysInterface{} public class EntityA: EntitysInterface { public string name { get; set; } } public class EntityB: EntitysInterface { public string title { get; set; } } public cla

我试图按顺序将Json对象反序列化为动态列表,因此:

Json:

.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() 
    {
    }
}
public interface EntitysInterface{}
公共类EntityA:EntitysInterface
{
公共字符串名称{get;set;}
}
公共类EntityB:EntitysInterface
{
公共字符串标题{get;set;}
}
公共类实体
{
公共列表元素{get;set;}//EntityA,EntityB,。。。
公共实体()
{
}
}
我的反序列化对象问题:

Entitys listFinaly = JsonConvert.DeserializeObject<Entitys>(json); 
Entitys listFinaly=JsonConvert.DeserializeObject(json);

Exception”类型是一个接口或抽象类,无法实例化。(“

JSON.NET反序列化程序告诉您,它无法确定您希望选择的接口对象是哪个
实体。它需要您给它一个提示

ContractResolver
有助于给出提示

编辑:


在JSON.Net文档中有一个错误。

如果
JsonConvert
在解析JSON字符串时不会引发异常,我可能会尝试提供帮助
Entitys listFinaly = JsonConvert.DeserializeObject<Entitys>(json);