我有一個類,像這樣:反序列化與自定義對象屬性對象
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