我制作了一个用于反序列化JSON的代码,所有内容都适用于某些内容,但对于此link我收到此错误:
注意:未定义的偏移量:第12行的C:\ xampp \ htdocs \ SF \ Teams.php中的0
就在这一行:$current_object = $decoded[$i];
这是我的代码:
$variable = file_get_contents("http://api.football-data.org/alpha/soccerseasons/351/teams");
$decoded = json_decode($variable, true);
for ($i = 0; $i < count($decoded); $i++) {
$current_object = $decoded[$i];
var_dump($current_object); ...
答案 0 :(得分:1)
以下代码输出team name
和Short name
尝试示例
$variable = file_get_contents("http://api.football-data.org/alpha/soccerseasons/351/teams");
$decoded = json_decode($variable, true);
foreach($decoded['teams'] as $team)
{
echo "Team name: ".$team['name']."<br />";
echo "Short name: ".$team['shortName']."<br />";
echo "<hr>";
}