2016-02-13 170 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