c# - C# - 无法反序列化当前 JSON 对象
问题描述
我知道有很多关于这个的线程,但我不明白这个 json 输出。我之前已经设法从这个站点反序列化 json,但它们不同。
我的课看起来像这样:
public class Bids
{
public string bids { get; set; }
public string asks { get; set; }
public string lastUpdateId { get; set; }
}
下载数据:
var depth = w.DownloadString("https://api.binance.com/api/v1/depth?symbol=BTCUSDT&limit=20");
反序列化:
var book = JsonConvert.DeserializeObject<Bids[]>(depth);
“无法反序列化当前 JSON 对象”
数据(https://api.binance.com/api/v1/depth?symbol=BTCUSDT&limit=20)如下所示:
{"lastUpdateId":192569803,"bids":[["6525.40000000","0.62166200",[]],["6524.40000000","0.04081700",[]],["6524.39000000","2.53414400",[]],["6524.13000000","0.53788600",[]],["6523.84000000","3.00000000",[]]],"asks":[["6527.00000000","1.54106400",[]],["6527.51000000","0.37739500",[]],["6527.53000000","0.31064700",[]],["6528.61000000","0.15400000",[]]]}
解决方案
您可以通过使用出色的Json2Csharp之类的东西来了解您的课程应该是什么样子,您还可以使用 VS paste special 'paste as json..'
这是该类的外观。不要忘记更新列表!
public class RootObject
{
public int lastUpdateId { get; set; }
public List<List<object>> bids { get; set; }
public List<List<object>> asks { get; set; }
}
推荐阅读
- apache-httpclient-4.x - 带有JDK11错误的Spring RestTemplate发布超过一定限制的数据
- wordpress - 嵌套简码?
- linux - 第一次尝试运行 vagrant up aws 时出现错误未定义的方法 `except' (NoMethodError)
- html - 滚动条不适用于鼠标滚轮且样式不正确
- javascript - npm 卡在“正在启动开发服务器...”
- c# - 使用 Try Catch 处理逻辑
- r - 如何更改ggplot中图例的样式,使每个元素周围都有一个矩形?
- python - 解析对象树的类结构
- python - forkserver 不在子进程中重用
- node.js - 有人知道为什么即使一切都通过了测试,mocha 还是会抛出错误?