我有一個類定製反序列化使用Json.NET
public class Order
{
public int Id { get; set; }
public string ShippingMethod { get; set; }
}
,我想下面的反序列化一個JSON數據到上面的類/對象
string json = @"{
'Id': 1,
'ShippingMethod': {
'Code': 'external_DHLExpressWorldwide',
'Description': 'DHL ILS Express Worldwide'
}
}";
我的想法是,在ShippingMethod
是JSON一個對象,但我只想在(JSON中)中進行反序列化,它將在Order
類中傳入ShippingMethod
,作爲string
。
我該如何使用Json.NET來實現該目標?
我相信我可以用來應付它。但我感到困惑。文檔中的示例僅適用於WriteJson
,但不適用於ReadJson
。
因此,'Code'和'Description'在'ShippingMethod'裏面?如何序列化? – Tinwor
你只需要在同一級別有「Id」和「Code」? – CodeNotFound
是的,那是我的問題,我想完成的事情 – Habibillah