我使用Steam登录到我的网站后出现此错误Notice: Trying to get property of non-object in /home/u852405559/public_html/index.php on line 178
。注意:试图获取非对象的属性 - json
178线是foreach((array)$json_decoded->response->players as $player) {
这里是168行至195请帮我
} elseif($openid->mode == 'cancel') {
echo 'User canceled auth';
} elseif($openid->validate()) {
$id = $openid->identity;
$ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
preg_match($ptn, $id, $matches);
$steamid = $matches[1];
$url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$_STEAMAPI&steamids=$steamid";
$json_object = file_get_contents($url);
$json_decoded = json_decode($json_object);
foreach((array)$json_decoded->response->players as $player) {
$url = "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=$_STEAMAPI&steamid=$steamid&format=json";
$json_object2 = file_get_contents($url);
$gamesOwned = json_decode($json_object2);
$ownsCSGO = 0;
foreach($gamesOwned->response->games as $game) {
if($game->appid == 730) {
$ownsCSGO = 1;
break;
}
}
if($ownsCSGO == 0) {
echo "<script> $(document).ready(function() { Materialize.toast('This steam account does not have CS:GO'); }); </script>";
} else {
建议json_decode不成功。试试'var_dump($ json_decoded);'并参见 – rjdown
@rjdown。检查var_dump值类型,即时猜测对象类型是数组 – AndreL
var_dump返回NULL –