我正在使用 Steam API 为游戏(appid)获取特定的 playtime_forever。这是我得到的 JSON 响应:
response: {
game_count: 7,
games: [
{
appid: 730,
playtime_2weeks: 300,
playtime_forever: 204909,
playtime_windows_forever: 48633,
playtime_mac_forever: 0,
playtime_linux_forever: 0
},
{
appid: 291550,
playtime_forever: 4905,
playtime_windows_forever: 4433,
playtime_mac_forever: 0,
playtime_linux_forever: 0
},
{
appid: 550650,
playtime_2weeks: 3,
playtime_forever: 12191,
playtime_windows_forever: 1405,
playtime_mac_forever: 0,
playtime_linux_forever: 0
},
{
appid: 573090,
playtime_forever: 2945,
playtime_windows_forever: 3,
playtime_mac_forever: 0,
playtime_linux_forever: 0
},
{
appid: 601510,
playtime_2weeks: 766,
playtime_forever: 47983,
playtime_windows_forever: 36461,
playtime_mac_forever: 0,
playtime_linux_forever: 0
},
{
appid: 222880,
playtime_forever: 284,
playtime_windows_forever: 3,
playtime_mac_forever: 0,
playtime_linux_forever: 0
},
]
}
我解码了 JSON 并遍历它,但我得到了错误
注意:试图在...中获取非对象的属性“响应”
这是我通过 JSON 循环的 PHP 代码
$json = json_decode(file_get_contents($api_game_stats), true);
$playtime ="";
foreach($json->response as $response){
foreach($response->games as $games){
if($games->appid==730){
$playtime = $games->playtime_forever;
}
}
}
如何正确循环通过该 JSON 响应?