How do you get an array from json text that has no square brackets in PHP? -


i trying data api result json has no square brackets, , looks

{   "status":1,   "time":42868,   "response":{     "some_item":"itemval1",     "itemstat":"itemstatvalue"   } } 

i'm trying array through json_decode, can't anywhere i've been trying hours...

$data = json_decode($result); 

by doing such data in large string, whenever try access such as

echo $data->time; 

or

echo $data[0]; 

i error saying 500 code invalid, i'm wondering how convert array can access these values. whenever echo $data though ridiculously large string full of of values need, can't access them.

try code below. then, able understand how json_decode works , how access properties.

you can see result here

<?php $s = '{   "status":1,   "time":42868,   "response":{     "some_item":"itemval1",     "itemstat":"itemstatvalue"   } }';  $object = json_decode($s);  var_dump($object);  echo php_eol . '------------------------' . php_eol;  $array = json_decode($s, true);  var_dump($array);  echo php_eol . '------------------------' . php_eol;  echo $object->response->some_item;  echo php_eol . '------------------------' . php_eol;  echo $array['response']['some_item']; 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -