MINOR Use json_decode() instead of the Services_JSON class if the function exists.

This commit is contained in:
simonwelsh 2011-12-10 08:57:45 +13:00
parent e20304276f
commit 3a006b77ae

View File

@ -170,10 +170,14 @@ class Convert {
* @return mixed JSON safe string
*/
static function json2obj($val) {
if(function_exists('json_decode')) {
return json_decode($val);
} else {
require_once(Director::baseFolder() . '/sapphire/thirdparty/json/JSON.php');
$json = new Services_JSON();
return $json->decode($val);
}
}
/**
* Convert a JSON string into an array.
@ -183,6 +187,9 @@ class Convert {
* @return array|boolean
*/
static function json2array($val) {
if(function_exists('json_decode')) {
return json_decode($val, true);
} else {
$json = self::json2obj($val);
if(!$json) return false;
@ -193,6 +200,7 @@ class Convert {
return $arr;
}
}
/**
* Converts an XML string to a PHP array