0

I am aware that this has been asked and answered, and I am looking at previous solutions

How to get String value from json_decode in php, PHP - cant get value with json_decode and a couple of other questions.

I have a json object that is being returned from a cURL call,

$tokenInfo = GetToken();
echo $tokenInfo; // <-- this prints out the values as I would expect to see it (shown below)
$tokenJson = json_decode($tokenInfo); // <-- this does not seem to decode
echo 'Getting Token Info:';
echo $tokenJson['access_token']; // <-- this does not give me my access token

The resposne from my server to get my access token is as below

{"access_token":"xxxxxxxxxxxxxxxx","token_type":"bearer","expires_at":1626180544,"expires_in":86400,"refresh_token":"yyyyyyyyyyyyyy"}

I am trying to get the access token from this response, and anytime I try and get this value its coming back as false and I cant for the life of me figure out why.

I would appreciate any guidance you may have as I have not worked with PHP in a long time and thought that this should be pretty straight forward.

3
  • 3
    json_decode returns an object, so you'll probably need echo $tokenJson->access_token Commented Jul 12, 2021 at 12:56
  • A dupe for you to understand the difference between decoding to object and to array. Commented Jul 12, 2021 at 12:57
  • 1
    you may want , sometime, to read the fabulous manual : php.net/manual/en/function.json-decode.php Commented Jul 12, 2021 at 12:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.