我使用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 –