【问题标题】:Capture json data from Steam API从 Steam API 捕获 json 数据
【发布时间】:2016-02-13 17:47:42
【问题描述】:

所以我要做的是从 Steams API 中为 dota2 英雄捕获/提取特定数据。我正在使用 C# 使用 this 方法来执行此操作。

https://api.steampowered.com/IEconDOTA2_570/GetHeroes/v0001/?key=2D13D618DA712015812E970165632F02&language=en_us

{
"result": {
    "heroes": [
        {
            "name": "npc_dota_hero_antimage",
            "id": 1,
            "localized_name": "Anti-Mage"
        },
        ]
}

这是我一直在尝试的代码:

WebClient c = new WebClient();
        var data = c.DownloadString("https://api.steampowered.com/IEconDOTA2_570/GetHeroes/v0001/?key=2D13D618DA712015812E970165632F02&language=en_us");

        JObject o = JObject.Parse(data);

        string heroname = (string)o["name"];

但它只返回一个错误,说“heroname”的值为空。

有什么想法吗?

【问题讨论】:

    标签: c# json api steam


    【解决方案1】:

    o 将是一个包含一个键的对象:resulto["result"] 将依次包含一个名为 heroes 的密钥。 o["result"]["heroes"] 是一个对象数组。所以o["result"]["heroes"][0] 将是第一项,o["result"]["heroes"][0]["name"] 是第一项的名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-20
      • 2019-01-05
      • 1970-01-01
      • 1970-01-01
      • 2021-02-25
      • 1970-01-01
      • 2014-07-24
      • 2023-03-20
      相关资源
      最近更新 更多