I have a class
public class Order
{
public int Id { get; set; }
public string ShippingMethod { get; set; }
}
and I want to deserialize a JSON data below into the above class/object
string json = @"{
'Id': 1,
'ShippingMethod': {
'Code': 'external_DHLExpressWorldwide',
'Description': 'DHL ILS Express Worldwide'
}
}";
My idea is that ShippingMethod
in JSON is a object, but I just want to get to ShippingMethod.Code
(in JSON) that will pass into ShippingMethod
as string
in Order
class during deserialization.
how can I accomplish that goal using Json.NET?
I believe I can accomlish it using CustomJsonConverter. But I get confused. The example in the docs just for WriteJson
, but not ReadJson
.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…