我怎样才能得到所有“steamids”来自哪里“游戏ID”存在并且具有值“730”的玩家? 它表明:
注意未定义的属性:stdClass的:: $游戏ID上线人数31 因为 “游戏ID” 犯规存在于每一个元素PHP的Json解码对象存在
代码:
$players = json_decode(file_get_contents("test.json"));
foreach($players->response->Players as $mydata)
{
if($players->gameid == "730"){
echo $mydata->steamid . "\n";
}
}
我的JSON:
{
"response": {
"players": [
{
"steamid": "76561198273176399",
"loccountrycode": "US"
},
{
"steamid": "76561198386141115",
"gameid": "730",
"loccountrycode": "DE"
},
{
"steamid": "76561198019025166",
"gameid": "730",
"loccountrycode": "RU"
},
{
"steamid": "76561198010529217",
"loccountrycode": "DK"
}
]
}
}
非常感谢。最好的祝福。
在foreach和'if mydata-> gameid'开头'''小号字母'''''''mydata-> gameid' – splash58
@ splash58 谢谢,但它显示我:NOTICE未定义的属性:stdClass :: $ gameid在第31行,因为“gameid”存在于每个元素 – Maro