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!
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).
Usually this means you have a character that is illegal. For instance using øæå will cause json_decode to return 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.