-5
我试图让这段代码的工作,但我不断收到此错误:试图让非对象JSON的财产在PHP
试图让非对象的属性..
我验证了我的json
对象,但仍然没有运气。我搜索了这个问题,但没有找到任何解决方案。我的代码第一部分,其创建JSON
和打印:
$response['team']['tid'] = $teamData['tid'];
$response['team']['name'] = $teamData['name'];
$response['team']['wins'] = $teamData['wins'];
$response['team']['group'] = $teamData['tgroup'];
$otherTeamNames = $db->query("SELECT name from teams where tgroup= '$teamData[4]'");
while($values = $otherTeamNames->fetch(PDO::FETCH_ASSOC)){
if($values['name'] != $teamData['name'])
$response['team']['otherteam'][] = $values;
}
$response['success'] = 1;
echo json_encode($response);
第二部分将在JSON
$json = file_get_contents('http://localhost/pract/getSingleTeamById.php', false, $context);
$teamInformation = json_decode($json);
$success = $teamInformation->{"success"};
解码之前的$json
解码输出:
{"team":{"tid":"2","name":"Italy","wins":"4","group":"D","otherteam":[{"name":"Uruguay"},{"name":"England"}]},"success":1}
任何帮助将不胜感激。
我确实尝试过这种方法,它给了我完全相同的错误。 –
你可以只是回声$ json和检查评论休息2行 –
[已更新]我再次使用它,它给了我什么,但好消息是错误不再存在...只是空输出。 –