我试图使用一个 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) 会产生正确的客户数量,但所有数据都为空。
执行 CustomerList(如下)会导致“无法反序列化当前 JSON 数组”异常
public class CustomerList
{
public List<Customer> customer { get; set; }
}
想法?