-2
因此,这里是json
file解析JSON后的输出为阵列()
我需要在HTML页,内标头标记来显示name
,score
,warsWon
,WarsLost
。
而且我需要在HTML表显示userName
,role
,level
的所有球员。
我使用下面的代码,但输出是array()
<?php
$a = 'http://185.112.249.77:9999/Api/Clan?clan=274879547254'; // place your JSON here. If string, add signle quotes around it.
$arr = json_decode($a, TRUE);
$names = $arr['name'];
$score = $arr['score'];
$warsWon = $arr['warsWon'];
$warsLost = $arr['warsLost'];
$users = array();
if (! empty($arr['players'])) {
foreach ($arr['players'] as $player) {
$users[$player['avatar']['userId']]['userName'] = $player['avatar']['userName'];
$users[$player['avatar']['userId']]['role'] = $player['avatar']['role'];
$users[$player['avatar']['userId']]['level'] = $player['avatar']['level'];
}
}
echo '<pre>';
print_r($users);
echo '</pre>';
?>
Here是上面代码的输出
谁能告诉我什么是错误?
删除[ '阿凡达']从$播放器[ '阿凡达'] [ '用户名'] –
看起来json_decode()想要JSON,但你给它一个URL。首先获取JSON数据,然后将结果传递给json_parse()。 –
我试过了,但它仍然不能正常工作。 – user3452599