【发布时间】:2015-01-16 07:18:53
【问题描述】:
我正在使用 Newtonsoft json 序列化程序将 json 字符串转换为对象。我的 json 结构如下 -
{
"EmployeeRecords": {
"12": {
"title": "Mr",
"Name": "John"
},
"35":{
"title": "Mr",
"Name": "Json"
}
}
}
我希望这个 Json 被序列化到下面的类中 -
public class Employee
{
public string EmployeeNumber { get; set; }
public string title { get; set; }
public string Name { get; set; }
}
public class EmployeeRecords
{
public List<Employee> Employees { get; set; }
}
这里的 Employeenumber 是 12 和 35。
请指导我如何编写自定义序列化程序,它将从父节点读取员工编号并将其包含在子节点的 EmployeeNumber 属性中。
【问题讨论】:
-
尝试使用这个解决方案:stackoverflow.com/questions/7895105/…
-
业务规则是否要求您创建该 JSON?它是有效的,但它非常不标准。
-
可以修改 JSON 吗?不要重新发明轮子!在匹配的类中序列化 JSON,然后将该类转换为您想要的类。
-
无法使用某些 CQ5 工具修改业务提供的 JSON
标签: c# json serialization json.net jsonserializer