The problem is to get an object result instead of array in json.
here is my code :
JavaScript
x
$response = $obj->toArray();
$encoded = json_encode($response, true);
header('Content-type: application/json');
exit($encoded);
and the result is somtimes like :
JavaScript
[ {"id":"1","value":"COM1"} , {"id":"2","value":"COM2"} ]
and I want it a pure json like :
JavaScript
{ "0" : {"id":"1","value":"COM1"} , "1" : {"id":"2","value":"COM2"} }
Advertisement
Answer
Try something like this:
JavaScript
json_encode( $array, JSON_FORCE_OBJECT )
That will return everything encased in { }