【发布时间】:2016-03-21 15:05:45
【问题描述】:
我正在尝试反序列化此 JSON,但我不断收到错误消息。有人可以帮帮我吗?我哪里做错了?
JSON:
{
"totalItems": 63,
"items": [
{
"id": 100039812,
"group": {
"code": "DD",
"description": "Delivery Documents"
},
"type": {
"code": "READ",
"description": "Logs"
},
"reference": "ARLDR",
"date": "2015-03-24T00:00:00",
"description": "ALogs",
"notes": "",
"lastUpdateDate": "2015-03-24T14:06:42.063",
"location": "BOX A001",
"metadata": {}
},
{
"id": 100039813,
"group": {
"code": "DD",
"description": "Delivery Documents"
},
"type": {
"code": "BL",
"description": "Logbooks"
},
"reference": "BALB",
"date": "2015-03-24T00:00:00",
"description": "Logbooks",
"notes": "",
"lastUpdateDate": "2015-03-24T14:07:42.44",
"location": "BOX A001",
"metadata": {}
}
]
}
public class Documents
{
public int totalItems { get; set; }
public List<doc_items> items { get; set; }
}
public class doc_items
{
public int id { get; set; }
public List<group_items> group { get; set; }
public List<type_items> type { get; set; }
public string reference { get; set; }
public string date { get; set; }
public string description { get; set; }
public string notes { get; set; }
public string lastUpdateDate { get; set; }
public string location { get; set; }
public List<metadata_list> metadata { get; set; }
}
public class group_items
{
public string code { get; set; }
public string description { get; set; }
}
public class type_items
{
public string code { get; set; }
public string description { get; set; }
}
public class metadata_list
{
}
然后我称之为:
Documents myDocuments = JsonConvert.DeserializeObject<Documents>(responsetext.ToString());
并收到以下错误:
错误:Newtonsoft.Json.JsonSerializationException: 无法将当前 JSON 对象(例如 {"name":"value"})反序列化为 System.Collections.Generic.List`1[AerData.Ranorex.Web.Records.API_Documents+Documents]' 类型,因为该类型需要 JSON 数组(例如 [...
【问题讨论】:
-
使用编辑 -> 选择性粘贴 -> 将 JSON 粘贴为类,或使用 jsonutils.com 将您的 json 字符串粘贴到新的类文件中 - 您的类不完全匹配
标签: c# json serialization deserialization