【发布时间】:2016-12-27 05:02:15
【问题描述】:
我正在尝试使此代码正常工作,但我不断收到此错误:
试图获取非对象的属性..
我已经验证了我的 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}
任何帮助将不胜感激。
【问题讨论】: