symfony json api for loop empty


symfony json api for loop empty

我正在尝试从symfony中的API获取数据。这是我的代码:

$champion_details_json = file_get_contents('https://global.api.pvp.net/api/lol/static-data/euw/v1.2/champion?api_key=mykey');
$obj2 = json_decode($champion_details_json);
$championDetailData = $obj2->data;

return $this->render('default/action.html.twig', compact('championData', 'championDetailData'));

这是 var 转储在屏幕上向我显示的内容:

object(stdClass)[386]
public 'Thresh' => 
object(stdClass)[385]
  public 'id' => int 412
  public 'key' => string 'Thresh' (length=6)
  public 'name' => string 'Thresh' (length=6)
  public 'title' => string 'the Chain Warden' (length=16)
public 'Aatrox' => 
object(stdClass)[387]
  public 'id' => int 266
  public 'key' => string 'Aatrox' (length=6)
  public 'name' => string 'Aatrox' (length=6)
  public 'title' => string 'the Darkin Blade' (length=16)

以下是 API 告诉我我回来的内容:

{
"data": {
  "Aatrox": {
     "id": 266,
     "title": "the Darkin Blade",
     "name": "Aatrox",
     "key": "Aatrox"
  },
  "Thresh": {
     "id": 412,
     "title": "the Chain Warden",
     "name": "Thresh",
     "key": "Thresh"
  },

使用json_decode($champion_details_json, true); true标志返回数组而不是对象