Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MINOR Use json_decode() instead of the Services_JSON class if the fun…

…ction exists.
  • Loading branch information...
commit 3a006b77ae8ed3af01d7029ff2be73fd3ca6e5f5 1 parent e203042
@simonwelsh simonwelsh authored
Showing with 19 additions and 11 deletions.
  1. +19 −11 core/Convert.php
View
30 core/Convert.php
@@ -170,9 +170,13 @@ static function array2json($val) {
* @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 @@ static function json2obj($val) {
* @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;
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.