-2

I have this JSON array data

{"accessToken":"eyJhbGciOiJSUzUxMiJ9.e","refreshToken":"QErx0bUxyx6wxFj5AXcAh21UuyO8ad/ULIaGlP3LU2lmXGnx0twbYdM+nJyfwAcK9Av50uZ3fSZ/2nhJwIi+bA==","expiresIn":"2021-11-11T10:20:33Z","issuedAt":"2021-11-11T10:05:33Z","tokenType":"Bearer"}

How do I get only accessToken object from the array. i.e yJhbGciOiJSUzUxMiJ9.e

This is how I have tried

$response = curl_exec($curl);

curl_close($curl);
$token = $response['accessToken'];
echo $token;

But I get this error

Warning: Illegal string offset 'accessToken'
Dominic
  • 341
  • 4
  • 15

2 Answers2

0
$response = curl_exec($curl);

curl_close($curl);
$data = json_decode($response, true);
echo $data['accessToken'];
bassxzero
  • 4,838
  • 22
  • 34
-1

try this before trying to access the array

json_decode($response, true);
I.Dzinka
  • 44
  • 1
  • 4