最佳答案
我有另一个子类派生自基类/接口
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class Employee : Person
{
public string Department { get; set; }
public string JobTitle { get; set; }
}
public class Artist : Person
{
public string Skill { get; set; }
}
List<Person> people = new List<Person>
{
new Employee(),
new Employee(),
new Artist(),
};
我如何反序列化以下Json回到List<人>
[
{
"Department": "Department1",
"JobTitle": "JobTitle1",
"FirstName": "FirstName1",
"LastName": "LastName1"
},
{
"Department": "Department2",
"JobTitle": "JobTitle2",
"FirstName": "FirstName2",
"LastName": "LastName2"
},
{
"Skill": "Painter",
"FirstName": "FirstName3",
"LastName": "LastName3"
}
]
我不想使用TypeNameHandling JsonSerializerSettings。我特别寻找自定义JsonConverter实现来处理这个问题。关于这方面的文档和示例在网上非常少。我似乎不能得到覆盖的ReadJson()方法实现在JsonConverter的权利。