[英]C# - Cannot deserialize the current JSON object
I know there's many threads about this but I don't understand this json output. 我知道有很多关于此的线程,但是我不理解这个json输出。 I have managed to deserialize json from this site before but they differ.
我曾经设法从该站点反序列化json,但是它们有所不同。
My class looks like this: 我的课看起来像这样:
public class Bids
{
public string bids { get; set; }
public string asks { get; set; }
public string lastUpdateId { get; set; }
}
Download data: 下载数据:
var depth = w.DownloadString("https://api.binance.com/api/v1/depth?symbol=BTCUSDT&limit=20");
Deserialize: 反序列化:
var book = JsonConvert.DeserializeObject<Bids[]>(depth);
"Cannot deserialize the current JSON object" “无法反序列化当前JSON对象”
Data ( https://api.binance.com/api/v1/depth?symbol=BTCUSDT&limit=20 ) looks like this: 数据( 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",[]]]}
You can get an idea as to what, your class should look like by using something like the excellent Json2Csharp , you can also use VS paste special 'paste as json..' 您可以通过使用类似出色的Json2Csharp之类的东西来了解类的外观,也可以使用VS粘贴特殊的“粘贴为json。”。
Here's how the class should look. 这是课程的外观。 dont forget to new up the lists!
不要忘记更新列表!
public class RootObject
{
public int lastUpdateId { get; set; }
public List<List<object>> bids { get; set; }
public List<List<object>> asks { get; set; }
}
Change your class to this: 将您的班级更改为此:
public class RootObject
{
public int lastUpdateId { get; set; }
public List<List<object>> bids { get; set; }
public List<List<object>> asks { get; set; }
}
And then DeserializeObject but I am not sure how to access List<List<object>>
data! 然后是DeserializeObject,但我不确定如何访问
List<List<object>>
数据!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.