2017-03-06 3 views
0

enter code hereこのコードが返され、エラーがRiot APIからの召喚者のためにこの変数をどのように作成するのが間違っていますか?

か「:未定義のプロパティ:stdClassの:: $名のメッセージ」「非オブジェクトのプロパティを取得しようとする」です。

変数$ summonerは機能しません。変数sID、$ lcaseregionおよび$ APIkey(など)がすべて適切に設定されていると仮定します。

<?php 
    $summonerURL = "https://$lcaseRegion.api.pvp.net/api/lol/$lcaseRegion/v1.4/summoner/" . $sID . "?api_key=9" . $APIkey; 
    $responseSummoner = @file_get_contents($summonerURL); 
    $summoner = @json_decode($responseSummoner); 
    echo print_r($summoner); //this works and prints things 
    echo $summoner->name; //this does not work 
    echo $summoner->profileIconId; //this also does not work. 
    //please find print_r results below... 
    ?> 

print_r results;

stdClass Object ([41245441] => stdClass Object ([id] => 41245441 [name] => Bubbalubagus [profileIconId] => 558 [revisionDate] => 1488775287000 [summonerLevel] => 30)) 

使用すると、配列がどのように機能するかに私を与えることができ、任意の他のアドバイスやヒントもいただければ幸いです。

+0

今の成功を働き、私には、成功裏にはstdClassオブジェクト配列にprofileIconId(番号)と名前だけでなく、任意の他のコンテンツを印刷することを意味します。 – Bubbalubagus

+0

これはオブジェクトのオブジェクトです。 'foreach'または' pop'で試してみてください。 –

答えて

-1

これを試してみてください:それはすでに指摘したとおり

// EDIT(それは一つだけですが)

$summoners = @json_decode($responseSummoner); 
foreach($summoners as $summoner){ 
    echo $summoner->name; 
    echo $summoner->profileIconId; 
} 

は、あなたが見つけ召喚をループする必要があります。そこ波平オブジェクトを見ました、これは、この質問に

関連する問題