Skip to content
Derek Jones edited this page Jul 5, 2012 · 13 revisions

Category:Helper::Community | Category:Helper::JSON The JSON helper is a simple interface to the Pear Services_JSON class created by Michal Migurski, Matt Knapp, and Brett Stimmerman.

Only two functions exist, json_encode and json_decode. Both functions take one parameter, the data to be encoded/decoded.

Once data is encoded, it is decoded in Javascript as so (javascript brackets should be parentheses):

//PHP
$data['encoded_data'] = json_encode($my_data);
$this->load->view('my_view', $data);

//Javascript
eval["var decoded_data = " + <?php echo $encoded_data; ?>];

Save the two attached files to your system/helpers directory. Load it like any other helper:

$this->load->helper('json');

I think it is better if you put the JSON.php file and the helper to the application/helper directory. Also note, that from PHP 5.2+ upwards the json_encode and json_decode() functions are compiled into core. So a small check would come handy. I have made those changes - download them from here: File:json_helper_pengekcs.zip

** The .php file downloads do not work as expected, however, I have left them up for Rick's examination. In the mean time, use the .txt downloads but rename them to .php after you have downloaded them. File:json_helper.txt File:JSON.txt

File:json_helper.php File:JSON.php

Clone this wiki locally