我目前正在玩一些 php 和 JSON,我对 PHP 几乎一无所知,但我设法达到了我需要的一半,目前我有这部分代码。
<?php
$json = file_get_contents('http://eu.battle.net/api/wow/character/Ragnaros/Smoosher?fields=progression');
$data = json_decode($json, true);
foreach ($data['progression']['raids'] as $raid) {
echo "Raid: ", $raid['name'];
echo " Normal: ", $raid['normal'];
echo " Heroic: ", $raid['heroic'];
echo " id: ", $raid['id'];
echo " Boss's: ", $raid['bosses']['name'];
?>
<p>
<?php
};
foreach ($data['progression']['raids']['bosses'] as $boss) {
echo " Boss Name: ", $boss['name'];
}
print_r($boss);
#echo $data->name;
?>
现在第一个 foreach 工作正常,没有问题将数据拉到页面中,但是我注意到这似乎是另一个(数组?)在我输出的那个中,所以我首先尝试了
echo " Boss's: ", $raid['bosses']['name'];
它只输出boss's这个词,也没有从数组中输出任何内容,所以我想也许我需要另一个foreach语句并开始通过它。然而这部分
foreach ($data['progression']['raids']['bosses'] as $boss) {
echo " Boss Name: ", $boss['name'];
}
给出错误
Warning: Invalid argument supplied for foreach() in xxxxxx/xx/xxxxx/wow/test.php on line 22
而且我看不出我做错了什么:(任何帮助都会很棒,我从中提取的json是
http://eu.battle.net/api/wow/character/Ragnaros/Smoosher?fields=progression