stdClass Object (
[api] => stdClass Object (
[results] => 1
[leagues] => stdClass Object (
[1] => stdClass Object (
[league_id] => 1
[name] => World Cup
[country] => World
[country_code] =>
[season] => 2018
[season_start] => 2018-06-14
[season_end] => 2018-07-15
[logo] => https://media.api-football.com/leagues/1.png
[flag] =>
[standings] => 1
)
)
)
)
$data= json_decode($response,false);
我必须阅读元素[league_id]
我试图写
echo $data->api->leagues[1]->league_id;
也请参见前面的示例,但是 什么都没印出来,我听不懂我错了。有人可以帮我吗,谢谢?谢谢
答案 0 :(得分:1)
leagues
是一个对象,而不是数组,因此您需要使用->
来访问该属性。并且由于它是数字而不是标识符,因此必须将属性名称括在大括号中。
echo $data->api->leagues->{"1"}->league_id;
答案 1 :(得分:0)
如果将第二个参数从json_decode
更改为true,也许您将通过以下方式访问:
echo $data['api']['leagues']['1']['league_id'];