我知道有很多与此相关的主题,但是我不理解这个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",[]]]}
答案 0 :(得分:1)
您可以通过使用类似出色的Json2Csharp之类的东西来了解类的外观,也可以使用VS粘贴特殊的“粘贴为json ..”
这是班级的样子。不要忘记更新列表!
public class RootObject
{
public int lastUpdateId { get; set; }
public List<List<object>> bids { get; set; }
public List<List<object>> asks { get; set; }
}
答案 1 :(得分:0)
将您的课程更改为此:
public class RootObject
{
public int lastUpdateId { get; set; }
public List<List<object>> bids { get; set; }
public List<List<object>> asks { get; set; }
}
然后是DeserializeObject,但我不确定如何访问List<List<object>>
数据!