1

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']['key'];

what is printed is "{";

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

hahahah wow, i work with json all the time, flipping hardcore brain fart. thanks man i appreciate that. wow i feel stupid
We all have a few slip ups every now and then. (:
2
$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'];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.