0
私はAPIからデータを取得する方法を改善したいと考えています。この場合、私はSteam APIからすべてのapp-idを取り出し、1行に1つずつ.txtファイルでリストしたいと考えています。みんなをフェッチするには無限の(または非常に高い)ループ(すべての反復の後で++
)が必要ですか?つまり、id 0から数えて、例えばforeach
-loopとなるでしょうか?私は年齢がかかり、悪い習慣のように聞こえると思っています。json api配列からPHPを使用してすべて取得する
http://api.steampowered.com/ISteamApps/GetAppList/v0001の応答からすべてのappidを{"appid:" n}
にするにはどうすればよいですか?
<?php
//API-URL
$url = "http://api.steampowered.com/ISteamApps/GetAppList/v0001";
//Fetch content and decode
$game_json = json_decode(curl_get_contents($url), true);
//Define file
$file = 'steam.txt';
//This is where I'm lost. One massive array {"app": []} with lots of {"appid": n}.
//I know how to get one specific targeted line, but how do I get them all?
$line = $game_json['applist']['apps']['app']['appid'][every single line, one at a time]
//Write to file, one id per line.
//Like:
//5
//7
//8
//and so on
file_put_contents($file, $line, FILE_APPEND);
?>
ちょうど右方向への任意のポインティングがはるかに理解されるであろう。ありがとう!
哀れな試みだけでも、非常に良い試みをしなかったことを非常に残念に思います。なぜなら私は。 –
foreachループを使用するカウンタはまったく必要ありません。 – rjdown
jsonは非常に簡単です。リストを抽出するだけです! $ line = $ game_json ['applist'] ['apps'] ['app']。それでおしまい ! – cpugourou