我正在尝试使用一个API,它返回的JSON数据遵循以下示例结构
[
{
"customer":{
"first_name":"Test",
"last_name":"Account",
"email":"test1@example.com",
"organization":"",
"reference":null,
"id":3545134,
"created_at":"2013-08-06T15:51:15-04:00",
"updated_at":"2013-08-06T15:51:15-04:00",
"address":"",
"address_2":"",
"city":"",
"state":"",
"zip":"",
"country":"",
"phone":""
}
},
{
"customer":{
"first_name":"Test",
"last_name":"Account2",
"email":"test2@example.com",
"organization":"",
"reference":null,
"id":3570462,
"created_at":"2013-08-12T11:54:58-04:00",
"updated_at":"2013-08-12T11:54:58-04:00",
"address":"",
"address_2":"",
"city":"",
"state":"",
"zip":"",
"country":"",
"phone":""
}
}
]
JSON.net可以很好地处理以下结构
{
"customer": {
["field1" : "value", etc...],
["field1" : "value", etc...],
}
}
但我无法弄清楚如何让它与提供的结构相匹配。
使用默认的JsonConvert.DeserializeObject(content)可以得到正确数量的 Customer,但所有数据都为 null。
将内容转换为 CustomerList(如下所示)会导致“无法反序列化当前的 JSON 数组”异常。
public class CustomerList
{
public List<Customer> customer { get; set; }
}
您有什么想法?