2016-07-13 1 views
1

심포니의 API에서 데이터를 가져 오려고합니다.symfony json api for 루프가 비어 있습니다.

다음
$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 덤프가 화면에 나에게 보여주고 내용은 다음과 같습니다 : 여기 내 코드의 API의 날을 알려줍니다 무엇을

다음
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) 

이야 내가 돌아 오기 :

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

답변

1

사용 json_decode($champion_details_json, true); true 플래그가 객체 대신 배열을 반환합니다.

관련 문제