Skip to content
Snippets Groups Projects
Commit 430d05b0 authored by Michael Hamann's avatar Michael Hamann
Browse files

Use native PHP JSON functions when available

parent a365baee
No related branches found
No related tags found
No related merge requests found
......@@ -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)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment