Help extracting data from JSON result
I am having an issue retrieving the key from this JSON result returned from the last.fm api
this is what is being returned:
{"session":{"name":"mcbeav","key":"***************","subscriber":"1"}}
and i just need the key, but if i try to print_r or var_dump , nothing is displayed how would i go about doing so?
for example if i print_r($json['key']);
or if i print_r['session']['k开发者_高级运维ey'];
what is printed is "{";
just use the php function
$myJsonData = json_decode($myJsonString,true)
it will give you an assocative array like you have in your code (what the second arguement true is for)
Hope that is what you are looking for
$json = json_decode('{"session":{"name":"mcbeav","key":"eab5a0axxxxxxx0c3","subscriber":"1"}}');
echo $json->session->key;
Or if you want an array:
$json = json_decode('{"session":{"name":"mcbeav","key":"eab5a0axxxxxxx0c3","subscriber":"1"}}', true);
echo $json['session']['key'];
精彩评论