无法反序列化Json

时间:2017-10-24 16:25:04

标签: c# json parsing serialization gdax-api

我需要帮助我无法反序列化我的json

CMAKE_LIBRARY_PATH

我得到了:

  

发生了'System.Net.WebException'类型的未处理异常   System.dll中

其他信息:

  

远程服务器返回错误:(400)错误请求。

在这一行:

 var myWebClient = new WebClient();
 var js = new JavaScriptSerializer();
 var json = myWebClient.DownloadString("https://api.gdax.com/products/btc-usd/book?level=2");
 OrderBookContainerExmo container = js.Deserialize<OrderBookContainerExmo>(json);

1 个答案:

答案 0 :(得分:0)

正如评论中提到的那样,您需要将User-Agent添加到标题中。

var myWebClient = new WebClient();
var js = new JavaScriptSerializer();
myWebClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
var json = myWebClient.DownloadString("https://api.gdax.com/products/btc-usd/book?level=2");
OrderBookContainerExmo container = js.Deserialize<OrderBookContainerExmo>(json);