无法反序列化 Json
Cannot deserialize Json
我需要帮助我无法反序列化我的 json
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);
我得到:
An unhandled exception of type 'System.Net.WebException' occurred in
System.dll
附加信息:
The remote server returned an error: (400) Bad Request.
这一行:
var json = myWebClient.DownloadString("https://api.gdax.com/products/btc-usd/book?level=2");
正如评论中提到的,您需要将User-Agent添加到headers。
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);
我需要帮助我无法反序列化我的 json
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);
我得到:
An unhandled exception of type 'System.Net.WebException' occurred in System.dll
附加信息:
The remote server returned an error: (400) Bad Request.
这一行:
var json = myWebClient.DownloadString("https://api.gdax.com/products/btc-usd/book?level=2");
正如评论中提到的,您需要将User-Agent添加到headers。
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);