C# 从 URL 中检索 JSON

标签 c# json steam steam-web-api

我正在创建一个程序,获取各种 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/

相关文章:

c# - 单击 "Add"时选择新用户

Android Json结果处理

linux - 在 Linux 上正确设置 Valves Source SDK 2013

javascript - 通过socket.io发送给特定的人

python - Steam 套件如何工作?

c# - Dictionary<myField, myObject> 其中 myField 是 myObject 的成员

c# - 对象初始化可以简化:IDE0017

c# - 获取不规则形状纵横比的算法

json - 如何将 json 字符串转换为 scala 映射?

java - jcouchdb : svenson unable to parse json string