我有一个类,像这样:反序列化与自定义对象属性对象
public class CareTaker
{
public int Id {get; set;}
public string name {get; set;}
public DateTime? DateTrained {get; set;}
public Certification Certification {get; set;}
public List<Certification> ExpiredCertifications {get; set;}
}
public class Certification
{
public int Id {get; set;}
}
和我的JSON是像这样:
{
"id": 1,
"name": "Dogtor",
"dateTrained": "01 Feb 2017",
"certification": 2,
"expiredCertifications": [1,5]
}
我平时知道的JSON Certification
确实应该像"certification": { "id": 2}
,但是,我没有权限更改JSON,因此我必须弄清楚如何将接收到的内容("certification": 2
)转换为我的对象...有没有办法可以使用JavascriptSerializer或NewtonSoft执行此操作?
你的代码更改为'公共列表 expiredCertifications {获得;组; '',稍后将它解析到你的'Certification'类。 –
cramopy