我正在创建一个程序,获取各种 CS:GO 元素的 Steam 市场价格,并将它们相互比较。我无法将 Steam 市场 JSON 放入我的程序中。 Market JSON 这是我的代码:
using (WebClient webClient = new System.Net.WebClient())
{
WebClient n = new WebClient(); // <-- error on this line
string json = n.DownloadString("http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=P250%20%7C%20Valence%20(Factory%20New");
dynamic array = JsonConvert.DeserializeObject(json);
test.Text = array.lowest_price.ToString(); ;
}
实例化 WebClient()
时出现此错误:
An unhandled exception of type 'System.Net.WebException' occurred in System.dll
Additional information: The remote server returned an error: (500) Internal Server Error.
这甚至是一个有效的 JSON 吗?如果没有,是否有替代方案?我听说 backpack.tf 也有一个 api。这样会更好吗? 谢谢
最佳答案
看起来 URL 格式不正确。我刚试过http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Shadow%20Case并获得了良好的反响。
需要特别注意的是您网址中的括号。
关于C# 从 URL 中检索 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33620325/