我有以下代码:
$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'};注意:getSummonerByName需要一个名称,getSummoner使用ID。
编辑:以下是$decode_runes__:http://pastebin.com/6h2TX9t1的一个示例
编辑:以下是$grab_runes__:http://pastebin.com/V3MNtbFA的一个示例
我从所有东西中使用var_dump()获得值,但是当我进入var_dump() $grab_names时,就得到了返回值NULL。
我知道这件事可能正盯着我的脸,但我看不见^,所以我很感激任何人能指出这一点!
发布于 2014-03-01 00:41:02
谢谢您添加$grab_runes转储。通过使用字符串并将其粘贴到JSONLint中,您可以非常清楚地了解JSON结构。从这张图片中可以清楚地看到,在由JSON表示的根对象上没有name属性。
唯一的根属性是summonerId和pages。
因此,您的问题是JSON结构中不存在要访问它的JSON结构,所以当您解码并尝试访问它时,您当然会得到一个空值。
看起来有一个name属性嵌套得更深了一点。
所以,要访问它应该是这样的:
$decode_runes->pages[i]->name其中i是您感兴趣的page的索引(在您的数据中有几个)。
发布于 2014-03-01 00:27:09
通常这意味着你有一个不合法的角色。例如,使用json_decode将导致返回null。
Returns the value encoded in json in appropriate PHP type. Values true, false and null (case-insensitive) are returned as TRUE, FALSE and NULL respectively. NULL is returned if the json cannot be decoded or if the encoded data is deeper than the recursion limit.decode
https://stackoverflow.com/questions/22108327
复制相似问题