API에서 데이터를 가져 오는 방법을 개선하고 싶습니다. 이 경우 Steam API에서 모든 앱 ID를 가져 와서 .txt 파일에 한 줄에 하나씩 나열하고 싶습니다. ++
모든 사람을 가져 오기 위해 무한 (또는 매우 높은 수) 루프 ( 모든 반복 후)가 필요합니까? 내 말은, 예를 들어 foreach
-loop로 id 0에서 계산 ? 나는 그것이 오래 걸릴 것이라고 생각하고 매우 나쁜 연습처럼 들립니다.
http://api.steampowered.com/ISteamApps/GetAppList/v0001{"appid:" n}
의 응답에서 모든 appid 를 어떻게 얻 습니까?
<?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
루프 가있는 카운터에 대해 걱정할 필요가 없습니다. 카운터 는 개체의 각 항목을 통과하고 작업하도록 설계되었습니다 .
$file = "steam.txt";
$game_list = "";
$url = "http://api.steampowered.com/ISteamApps/GetAppList/v0001";
$game_json = file_get_contents($url);
$games = json_decode($game_json);
foreach($games->applist->apps->app as $game) {
// now $game is a single entry, e.g. {"appid":5,"name":"Dedicated server"}
$game_list .= "$game->appid\n";
}
file_put_contents($file, $game_list);
이제 28000 개의 숫자가있는 텍스트 파일이 있습니다. 축하합니다?
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다