如何在JSON.NET中实现自定义Json转换器以反序列化基类对象的列表?我试图扩展这里给出的JSON.net示例http:/james.newtonking.com/Projects/json/Help/CustomCreationConverter.html我有另一个派生自基类/接口的子类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之后返回列表<Person>[
{
"Department": "Department1",
"JobTitle": "JobTitle1",
"FirstName": "FirstName1",
"LastName": "LastName1"
},
{
"Department": "Department2",
"JobTitle": "JobTitle2",
"FirstName": "FirstName2",
"LastName": "LastName2"
},
{
"Skill": "Painter",
"FirstName": "FirstName3",
"LastName": "LastName3"
}]我不想使用TypeNameHandling JsonSerializerSettings。我特别需要定制的Json转换器实现来处理这个问题。这方面的文档和示例在网络上非常稀少。我似乎无法正确实现Json变换器中重写的ReadJson()方法实现。
3 回答
- 3 回答
- 0 关注
- 853 浏览
添加回答
举报
0/150
提交
取消