The “true” as a second parameter ended there because all the testing, took it out but nothing changes.
Question is, where do these quotes come from, as the extension doesn’t do much more then iterating over the object and calling json_encode()
They come from the to_json output, as you will see at next.
Now:
Controller:
$data['clientesjson'] = $clientes->all_to_json(array('id','apellido'));
$data['onejson'] = $clientes->to_json(array('id','apellido'));
$data['clientesarr'] = $clientes->all_to_array(array('id','apellido'));
$data['onearr'] = $clientes->to_array(array('id','apellido'));
echo var_dump($data['clientesjson']).'
';
echo var_dump($data['onejson']).'
';
echo var_dump($data['clientesarr']).'
';
echo var_dump(json_encode($data['clientesarr'])).'
';
echo var_dump($data['onearr']).'
';
echo var_dump(json_encode($data['onearr']));
browser output:
1st) string(116) “[”{\"id\":1,\"apellido\":\"Fulanito\"}”,”{\"id\":3,\"apellido\":\"Griffin\"}”,”{\"id\":2,\"apellido\":\"Simpson\"}”]”
2nd) string(30) “{"id":1,"apellido":"Fulanito"}”
3rd) array(3) { [0]=> array(2) { ["id"]=> int(1) ["apellido"]=> string(8) "Fulanito" } [1]=> array(2) { ["id"]=> int(3) ["apellido"]=> string(7) "Griffin" } [2]=> array(2) { ["id"]=> int(2) ["apellido"]=> string(7) "Simpson" } }
4th) string(92) “[{"id":1,"apellido":"Fulanito"},{"id":3,"apellido":"Griffin"},{"id":2,"apellido":"Simpson"}]”
5th) array(2) { ["id"]=> int(1) ["apellido"]=> string(8) "Fulanito" }
6th) string(30) “{"id":1,"apellido":"Fulanito"}”
The thing is that the 4th result is a valid array of three json objects (in json format), but the 1st (again in json format) is just an array of three strings.
I think that the problem is to make an array of json objects (enclosed each one between double quotes, because apparently that’s how json_encode works), and then json_encode this array (that’s what all_to_json).
I’m quite sure that all_to_json is not returning what is expected (an array of json objects) but an array of string that contains the data but has to be parsed ad hoc.
what do you think?
thanks again,