dox19458 2014-03-01 00:20
浏览 30
已采纳

JSON解码问题

I have the following code:

$instance = new riotapi($srg_lower);
    $grab_data = $instance->getSummonerByName($summoner_nm);
    $decode_data = json_decode($grab_data);
    $grab_id = $decode_data->{'id'};

    $grab_runes = $instance->getSummoner($grab_id,'runes');
    $decode_runes = json_decode($grab_runes);
    $grab_names = $decode_runes->{'name'};

Note: getSummonerByName requires a name, getSummoner uses the ID.

EDIT: Heres an example of $decode_runes: http://pastebin.com/6h2TX9t1

EDIT: Heres an example of $grab_runes: http://pastebin.com/V3MNtbFA

I get values from using var_dump() from everything but when I go to var_dump() $grab_names I get the return value NULL.

I understand that this issue might be staring me in the face, but I can't see it ^^; So I am grateful to anyone who can point it out!

  • 写回答

2条回答 默认 最新

  • doudi5892 2014-03-01 00:41
    关注

    Thanks for adding the $grab_runes dump. By taking the string and pasting it into JSONLint, you can get a very clear picture of your JSON structure. And what is clear from that picture, is that there is not a name property on the root object represented by the JSON.

    The only root properties are summonerId and pages.

    So your problem is name does not exist in the JSON structure where you are trying to access it, so when you decode it and try to access it, you are of course going to get a null value.

    It looks like there is a name property nested down a little further.

    So, to access it would be something like this:

    $decode_runes->pages[i]->name
    

    Where i is the index of the page you are interested in (there are several of these in your data).

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

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能