Batch Geocoder Call to undefined function json_dec

13 years 1 month ago #87 by stephen@melloncg.com
Batch Geocoder Call to undefined function json_dec was created by stephen@melloncg.com
I'm receiving the following error when attempting to use the batch geocoder. Doing them one off works, but I have 364 to go. I assume there is a component I failed to install:

Fatal error: Call to undefined function json_decode() in /httpdocs/administrator/components/com_storelocator/controllers/geocode.php on line 59

Thanks,

Please Log in to join the conversation.

  • stephen@melloncg.com
  • Topic Author
  • Offline
More
13 years 1 month ago #88 by sysgenmedia
Replied by sysgenmedia on topic Batch Geocoder Call to undefined function json_dec
Hi Stephen,

I believe your problem is because your version of PHP doesn't include JSON support. This is most likely due to having a version prior to 5.2.0. You should upgrade to a later version if this is true for security reasons, but if you don't or cant upgrade, you can try this solution:


1. Download JSON.php and put it in /administrator/components/com_storelocator/ –> http://mike.teczno.com/JSON.tar.gz

2. Add these lines at the bottom of JSON.php, but before “?>”
// Future-friendly json_encode
if( !function_exists(‘json_encode’) ) {
function json_encode($data) {
$json = new Services_JSON();
return( $json->encode($data) );
}
}
 
// Future-friendly json_decode
if( !function_exists(‘json_decode’) ) {
function json_decode($data, $bool) {
if ($bool) {
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
} else {
$json = new Services_JSON();
}
return( $json->decode($data) );
}
}

3. Import the new JSON library by adding this line at the top of storelocator.php, but under the security directive, so your file should look like this:
// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
include_once( 'JSON.php' );
 
// Require the base controller
 
require_once( JPATH_COMPONENT.DS.'controller.php' );

Let me know how that works out for you.

Please Log in to join the conversation.

More
13 years 1 month ago #89 by stephen@melloncg.com
Replied by stephen@melloncg.com on topic Batch Geocoder Call to undefined function json_dec
You are correct in that we are not running PHP 5.2, and your solution worked like a charm. The only issue we had was that in the code you provided the function_exists() calls had the arguments inside "ticks" (`) instead of single quotes ('), but that was easily corrected.

Thanks for the help!

Please Log in to join the conversation.

  • stephen@melloncg.com
  • Topic Author
  • Offline
More