【发布时间】:2021-06-03 14:51:58
【问题描述】:
responsestring = await response.Content.ReadAsStringAsync();
ClassifierResponse Response = JsonConvert.DeserializeObject<ClassifierResponse>(responsestring);
我的 json 响应是
{
"resultList": [
{
"modelId": 11,
"modelName": "indves12",
"modelLang": "US",
"modelVersion": 5,
"scoreMap": {
"individual": 0.401956,
"vessel": 0.598043
},
"bestCategory": "vessel"
}
]
}
我得到这个错误: Newtonsoft.Json.JsonSerializationException:'无法将当前 JSON 对象(例如 {"name":"value"})反序列化为类型 'System.Collections.Generic.List`1[System.String]',因为该类型需要 JSON 数组(例如 [1,2,3])正确反序列化。 要修复此错误,要么将 JSON 更改为 JSON 数组(例如 [1,2,3]),要么将反序列化类型更改为普通的 .NET 类型(例如,不是像整数这样的原始类型,而不是像这样的集合类型可以从 JSON 对象反序列化的数组或列表。也可以将 JsonObjectAttribute 添加到类型中以强制它从 JSON 对象反序列化。
【问题讨论】:
-
你能告诉我的课程
ClassifierResponse吗? -
现在将课程添加到问题中。@vernou
-
我是否应该像 ClassifierResponse
Response = JsonConvert.DeserializeObject >(responsestring); 那样添加结果列表来反序列化;
标签: c# json serialization deserialization