【发布时间】:2021-07-22 03:17:49
【问题描述】:
请帮助它打破我的大脑。
Newtonsoft.Json.JsonSerializationException: '无法将当前 JSON 对象(例如 {"name":"value"})反序列化为类型 'System.Collections.Generic.List`1[ExaAsset+UsersInBinList]' 因为该类型需要正确反序列化的 JSON 数组(例如 [1,2,3])。 要修复此错误,请将 JSON 更改为 JSON 数组(例如 [1,2,3])或更改反序列化类型,使其成为普通的 .NET 类型(例如,不是像整数这样的原始类型,而不是像可以从 JSON 对象反序列化的数组或列表。 JsonObjectAttribute 也可以添加到类型中以强制它从 JSON 对象反序列化。 路径 'topUsers.usersInBinList['dwm-2 (xxxx-xxx-10)'].username',第 1 行,位置 855。'
"usersInBinList": {
"dwm-2": {
"username": "dwm-2",
"fullName": "Service Account",
"riskScore": 4.82
}}
public class UsersInBinList
{
public string username { get; set; }
public string fullName { get; set; }
public string photo { get; set; }
public string title { get; set; }
public double riskScore { get; set; }
}
public class TopUsers
{
public string key { get; set; }
public string modelName { get; set; }
public string groupingFeatureValue { get; set; }
public string histSpan { get; set; }
public string histogramDate { get; set; }
public string histClassName { get; set; }
public double confidenceFactor { get; set; }
public int totalBinCount { get; set; }
public int totalCount { get; set; }
public long lastUpdate { get; set; }
public Hist hist { get; set; }
public Dictionary<string, List<UsersInBinList>> UsersInBinList { get; set; }
public PeerGroupsInBinList peerGroupsInBinList { get; set; }
public bool disabled { get; set; }
}
asset = JsonConvert.DeserializeObject<ExaAsset>(APIresponse);
UsersInBinList 的第一个键是用户名而不是“用户”等,因此我无法将其序列化为每个 API 响应的不同用户名...有什么想法吗?
【问题讨论】:
-
这能回答你的问题吗? Hashes Are Not Matching