假设我有这个类:
public class Resource
{
[JsonProperty(propertyName: "address")]
public Domain.DTO.Address Addresses { get; set; }
}
Json 字符串值如下所示:
{
.
.
.
"resourceSets":[
{
"estimatedTotal":1,
"resources":[
{
.
.
.
"address":{
"UserLocation":null,
"adminDistrict":"National Capital Region",
"adminDistrict2":"Third District NCR",
"locality":"Caloocan City",
"postalCode":null,
"addressLine":"Yellow Bell Ext",
"formattedAddress":"Yellow Bell Ext, Caloocan City, Philippines",
"neighborhood":"Barangay 161",
"landmark":null,
"countryRegion":"Philippines"
}
}
]
}
]
}
这会正确反序列化。但是在序列化资源类时,我希望将某些属性(如“地址”)序列化为“地址”而不是“地址”。
我曾尝试使用 DataMember,但没有奏效。任何想法?