0
我使用Json.net api JsonConvert.PopulateObject
它首先接受json字符串的两个参数,然后接受要填充的实际对象。使用Json.net自定义反序列化属性
,我想填充对象的结构
internal class Customer
{
public Customer()
{
this.CustomerAddress = new Address();
}
public string Name { get; set; }
public Address CustomerAddress { get; set; }
}
public class Address
{
public string State { get; set; }
public string City { get; set; }
public string ZipCode { get; set; }
}
我的JSON字符串是
{
"Name":"Jack",
"State":"ABC",
"City":"XX",
"ZipCode":"098"
}
现在Name
财产得到填补,原因是其存在于JSON字符串,但CustomerAddress
是没有得到填充。有什么办法可以告诉Json.net库,从City
属性填充CustomerAddress.City
json字符串?