MINOR Fixed regression of Convert::json2obj() not working when json_decode() is being used (from r100461)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@105571 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-05-25 03:53:58 +00:00
parent d5e48d55dc
commit dd7e7f813d

View File

@ -140,8 +140,7 @@ class Convert extends Object {
} }
/** /**
* Uses the PHP 5.2 native json_encode function if available, * Convert an array into a JSON encoded string.
* otherwise falls back to the Services_JSON class.
* *
* @see http://pear.php.net/pepr/pepr-proposal-show.php?id=198 * @see http://pear.php.net/pepr/pepr-proposal-show.php?id=198
* @uses Director::baseFolder() * @uses Director::baseFolder()
@ -161,8 +160,7 @@ class Convert extends Object {
} }
/** /**
* Uses the PHP 5.2 native json_decode function if available, * Convert a JSON encoded string into an object.
* otherwise falls back to the Services_JSON class.
* *
* @see http://pear.php.net/pepr/pepr-proposal-show.php?id=198 * @see http://pear.php.net/pepr/pepr-proposal-show.php?id=198
* @uses Director::baseFolder() * @uses Director::baseFolder()
@ -172,14 +170,10 @@ class Convert extends Object {
* @return mixed JSON safe string * @return mixed JSON safe string
*/ */
static function json2obj($val) { static function json2obj($val) {
if(function_exists('json_decode')) {
return json_decode($val);
} else {
require_once(Director::baseFolder() . '/sapphire/thirdparty/json/JSON.php'); require_once(Director::baseFolder() . '/sapphire/thirdparty/json/JSON.php');
$json = new Services_JSON(); $json = new Services_JSON();
return $json->decode($val); return $json->decode($val);
} }
}
/** /**
* Convert a JSON string into an array. * Convert a JSON string into an array.