2016-02-13 167 views
0

因此,我想要做的是从dom2英雄的Steams API中捕获/提取特定数据。我正在使用C#使用this方法执行此操作。从Steam API捕获json数据

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” 值为空。

任何想法?

回答

1

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

+0

令人惊讶的是,感谢您清理那个! – Jomasdf