我有两种格式的JSON,我想将它们反序列化为一个类.
我知道我们不能对一个属性应用两个[JsonProperty]
属性.
你能给我一个实现这个目标的方法吗?
string json1 = @"
{
'field1': '123456789012345',
'specifications': {
'name1': 'HFE'
}
}";
string json2 = @"
{
'field1': '123456789012345',
'specifications': {
'name2': 'HFE'
}
}";
public class Specifications
{
[JsonProperty("name1")]
public string CodeModel { get; set; }
}
public class ClassToDeserialize
{
[JsonProperty("field1")]
public string Vin { get; set; }
[JsonProperty("specification")]
public Specifications Specifications { get; set; }
}
I want name1
and name2
both to be deserialize to name1
property of specification class.