dongyu9894 2017-03-31 19:30
浏览 49

将RiotGames JSON API转换为PHP

I'm having an issue retrieving certain information from RiotGames API. The code shown below is me retrieving the wins and losses for game types (if available).

<?php   
    // get that summoner's wins and losses for each game type
    $result = file_get_contents('https://na.api.pvp.net/api/lol/na/v1.3/stats/by-summoner/' . $summoner->id . '/summary?api_key=' . $apiKey);
    $stats = json_decode($result);
    // var_dump($stats);
    foreach($stats->playerStatSummaries as $statSummary){
        // $statSummary->losses: sometimes losses isn't set
        $losses = property_exists($statSummary, 'losses')? $statSummary->losses : '(not available)';
        print '<p><b>' . $statSummary->playerStatSummaryType . '</b>: ' .
                $statSummary->wins . ' wins, ' . $losses . ' losses</p>';
    }
?>

It fetches the wins and losses of Riot's API and returns it. But if I try to grab something different such as totalAssists from their aggregatedStats and replace wins with totalAssists it will return false with this error

"type 8 -- Undefined property: stdClass::$totalAssists -- at line 35"

Why does this not work? (You can find all the information of RiotsAPI by clicking here and then clicking the second "GET" under "STATS-V1.3"

  • 写回答

1条回答 默认 最新

  • dongya4089 2017-03-31 20:00
    关注

    It might be possible that the total assists doesn't exist also.

    You said if you "replace wins with totalAssists" that you get an error. You need to check to see if wins exists too.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题