From 3a006b77ae8ed3af01d7029ff2be73fd3ca6e5f5 Mon Sep 17 00:00:00 2001 From: simonwelsh Date: Sat, 10 Dec 2011 08:57:45 +1300 Subject: [PATCH] MINOR Use json_decode() instead of the Services_JSON class if the function exists. --- core/Convert.php | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/core/Convert.php b/core/Convert.php index 0be48ac7d..965f7f103 100644 --- a/core/Convert.php +++ b/core/Convert.php @@ -170,9 +170,13 @@ class Convert { * @return mixed JSON safe string */ static function json2obj($val) { - require_once(Director::baseFolder() . '/sapphire/thirdparty/json/JSON.php'); - $json = new Services_JSON(); - return $json->decode($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); + } } /** @@ -183,15 +187,19 @@ class Convert { * @return array|boolean */ static function json2array($val) { - $json = self::json2obj($val); - if(!$json) return false; - - $arr = array(); - foreach($json as $k => $v) { - $arr[$k] = $v; + if(function_exists('json_decode')) { + return json_decode($val, true); + } else { + $json = self::json2obj($val); + if(!$json) return false; + + $arr = array(); + foreach($json as $k => $v) { + $arr[$k] = $v; + } + + return $arr; } - - return $arr; } /**