我正在尝试将 JSON 响应反序列化为不将 1 映射到 1 的对象。我尝试反序列化的 JSON 是
{
"CustomerID": "1",
"CustomerName": "John Doe",
"BillingAddressLine1": "1234 Main St",
"BillingAddressLine2": "APT. 5",
"BillingCity": "New York City",
"BillingState": "NY",
"BillingZip": "12345",
"BillingCountry": "USA",
"BillingAttention": "John Doe",
"MailingAddressLine1": "555 Main St",
"MailingAddressLine2": "P.O. Box 5",
"MailingCity": "New York City",
"MailingState": "NY",
"MailingZip": "12345",
"MailingCountry": "USA",
"MailingAttention": "Jane Doe"
}
我试图反序列化它的对象是
public class Customer
{
public int CustomerID{ get; set;}
[JsonProperty(PropertyName = "CustomerName")]
public string Name {get; set;}
public Address BillingAddress{get; set;}
public Address MailingAddress{get; set;}
}
public class Address
{
public string Line1 { get; set; }
public string Line2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Country { get; set; }
public string PostalCode { get; set; }
public string Attention { get; set; }
}
有没有一种方法可以通过使用 Newtonsoft JSON 反序列化器进行映射,或者这是否需要自定义映射函数?