【发布时间】:2017-05-18 18:21:28
【问题描述】:
在以下 JSON 响应方面需要帮助。我尝试反序列化
JSON 响应
{
"entities":[
{
"id":"/Severity/Critical",
"Name":"Critical"
},
{
"id":"/Severity/High",
"Name":"High"
},
{
"id":"/Severity/Low",
"Name":"Low"
},
{
"id":"/Severity/Normal",
"Name":"Normal"
}
],
"paging":{
"from":4,
"limit":100,
"hasMore":false
}
}
var severity = JsonConvert.DeserializeObject<Severity>(json);
错误信息
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'System.Collections.Generic.Dictionary`2[System.String,System.String]' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
要修复此错误,请将 JSON 更改为 JSON 对象(例如 {"name":"value"})或将反序列化类型更改为数组或实现集合接口的类型(例如 ICollection、IList),例如可以从 JSON 数组反序列化的列表。也可以将 JsonArrayAttribute 添加到类型中以强制它从 JSON 数组中反序列化。
【问题讨论】:
-
您应该考虑格式化您的帖子以使其更易于阅读。
标签: c# json serialization