0

getting a json file from an API now i need to use values in the array here's an example assuming

<?php
     $jsonData = {"responseCode":"8876","responseDetail":"success","accessToken":"098826sdftyajjla;"}

     $array = json_encode($jsonData);
     echo $array['accessToken'];
Gerald Mathabela
  • 475
  • 2
  • 4
  • 16

2 Answers2

1

you cannot access json_encoded data using arrays you must have to decode the json first and then you can access values e.g

$json_data = '{"response_code":200,"response_status":"success","accessToken":"abcdef"}';
$data = json_decode($json_data);
echo $data->accessToken;
Manvir Singh
  • 431
  • 4
  • 6
0

Please try this

    <?php 
         $jsonData = '{"responseCode":"8876","responseDetail":"success","accessToken":"098826sdftyajjla;"}';
         $array = json_decode($jsonData);
         print_r($array->accessToken );
?>