douxian9060 2015-04-02 09:29
浏览 28
已采纳

PHP | 访问对象中的对象

Hi I am very new to using API's with PHP. This is my first attempt. So far I have got the data being returned in a JSON format. I have the json_decoded() it and the var_dump() is returning what I can only work out as an object within an object. My PHP inexperience might be showing here.

Below is the code I am using which is successfully retrieving data.

    $url = 'https://euw.api.pvp.net/api/lol/euw/v1.4/summoner/by-name/elderofaegis?api_key=RemovedForSO';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_URL, $url);
    $output = curl_exec($ch);
    curl_close($ch);
    $result = json_decode($output);
    var_dump($result);

Below is what the var_dump() is returning

object(stdClass)[1]
  public 'elderofaegis' => 
     object(stdClass)[2]
      public 'id' => int 38186794
      public 'name' => string 'ElderOfAegis' (length=12)
      public 'profileIconId' => int 785
      public 'summonerLevel' => int 30
      public 'revisionDate' => float 1427933098000

Does anyone know how I could access the object by its name. By this i mean the sections contained within the quotes for example if i want to echo the name i want something along the lines of (Pseudo Below).

echo $result->object['name'];

The above example is Pseudo Because I can't figure it out. For anyone wondering this is the League Of Legends API

Thanks.

  • 写回答

2条回答 默认 最新

  • duanaoyuan7202 2015-04-02 09:32
    关注

    Try

    $result->elderofaegis->name;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比