我正在为 Omegle 写一些东西,这是我得到的回应:
{ "clientID" : "shard2:jgv1dnwhyffmld7kir5drlcwp7k6eu",
"events" : [ [ "waiting" ],
[ "statusInfo",
{ "antinudepercent" : 1.0,
"antinudeservers" : [ "waw1.omegle.com",
"waw2.omegle.com",
"waw3.omegle.com"
],
"count" : 28477,
"servers" : [ "front1.omegle.com",
"front8.omegle.com",
"front7.omegle.com",
"front9.omegle.com",
"front2.omegle.com",
"front5.omegle.com",
"front3.omegle.com",
"front6.omegle.com",
"front4.omegle.com"
],
"spyQueueTime" : 0.000099992752075199996,
"spyeeQueueTime" : 0.8086000442504,
"timestamp" : 1375197484.3550739
}
]
]
}
要将这些数据放入字典中,我尝试使用以下函数:
private Dictionary<string, object> deserializeToDictionary(string jo)
{
Dictionary<string, object> values = JsonConvert.DeserializeObject<Dictionary<string, object>>(jo);
Dictionary<string, object> values2 = new Dictionary<string, object>();
foreach (KeyValuePair<string, object> d in values)
{
if (d.Value.GetType().FullName.Contains("Newtonsoft.Json.Linq.JObject"))
{
values2.Add(d.Key, deserializeToDictionary(d.Value.ToString()));
}
else
{
values2.Add(d.Key, d.Value);
}
}
return values2;
}
但是,我收到以下错误:
无法将当前 JSON 数组(例如 [1,2,3])反序列化为类型“System.Collections.Generic.Dictionary2[System.String,System.Object]”,因为该类型需要 JSON 对象(例如 {"name": "value"}) 正确反序列化。
要修复此错误,请将 JSON 更改为 JSON 对象(例如 {"name":"value"})或将反序列化类型更改为数组或实现集合接口的类型(例如 ICollection、IList),例如可以从 JSON 数组反序列化。JsonArrayAttribute 也可以添加到类型中以强制它从 JSON 数组反序列化。
我究竟做错了什么?