summaryrefslogtreecommitdiff
path: root/inc/JSON.php
diff options
context:
space:
mode:
authorMichael Hamann <michael@content-space.de>2010-11-15 00:38:54 +0100
committerMichael Hamann <michael@content-space.de>2010-11-15 00:38:54 +0100
commit430d05b058ac3df435600a678cda365dba3eb1b7 (patch)
tree80a4c73199b022480fc3985f241bfbc15d305f97 /inc/JSON.php
parenta365baeef4fc0b6d593043c6db53c01671de9490 (diff)
downloadrpg-430d05b058ac3df435600a678cda365dba3eb1b7.tar.gz
rpg-430d05b058ac3df435600a678cda365dba3eb1b7.tar.bz2
Use native PHP JSON functions when available
Diffstat (limited to 'inc/JSON.php')
-rw-r--r--inc/JSON.php4
1 files changed, 4 insertions, 0 deletions
diff --git a/inc/JSON.php b/inc/JSON.php
index 332827f4c..d1fbd404a 100644
--- a/inc/JSON.php
+++ b/inc/JSON.php
@@ -130,6 +130,7 @@ class JSON {
/**
* encodes an arbitrary variable into JSON format
+ * If available the native PHP JSON implementation is used.
*
* @param mixed $var any number, boolean, string, array, or object to be encoded.
* see argument 1 to JSON() above for array-parsing behavior.
@@ -140,6 +141,7 @@ class JSON {
* @access public
*/
function encode($var) {
+ if (function_exists('json_encode')) return json_encode($var);
switch (gettype($var)) {
case 'boolean':
return $var ? 'true' : 'false';
@@ -352,6 +354,7 @@ class JSON {
/**
* decodes a JSON string into appropriate variable
+ * If available the native PHP JSON implementation is used.
*
* @param string $str JSON-formatted string
*
@@ -363,6 +366,7 @@ class JSON {
* @access public
*/
function decode($str) {
+ if (function_exists('json_decode')) return json_decode($str);
$str = $this->reduce_string($str);
switch (strtolower($str)) {