*** Update ***
I think I had a brain fart at the time when I was trying to get this to work. I hadn’t created the Services_JSON object.
Here’s the updated and working function found in my controller:
function ajax(){
log_message("debug","starting ajax");
$this->load->helper('json');
$json = new Services_JSON();
$msg = array("test"=>"a simple test");
$jobj = $json->encode($msg);
log_message("debug","json output: ".$jobj);
echo $jobj;
}
————Old Message Below——————-
I’m getting the following error when trying to use the JSON Helper from the wiki (http://www.codeigniter.com/wiki/JSON_Helper/).
Fatal error: Call to a member function on a non-object in C:\Apache\...\system\helpers\json_helper.php on line 49
Line 49 represents the following in the json_helper.php file:
return $json->encode($data);
I’ve also tried using what I’ve found from another helper for object management through CI (found below), but that didn’t work either. I’m not sure if what I tried is even possible, but thought it worth a try.
$obj =& get_instance();
$obj->json= new Services_JSON();
$obj->ci_is_loaded[] = 'json';
Here’s the function call that starts the whole thing:
function ajax(){
// used to get dropdown data
log_message("debug","starting ajax");
$this->load->helper('json');
$msg = array("test"=>"a simple test");
$jobj = json_encode($msg);
log_message("debug","json output: ".$jobj);
}
Any info on fixing my problem would be greatly appreciated.