public static function decode($string, $returnArrays = false)
    {
        $result = json_decode($string, $returnArrays);

        if (function_exists('json_last_error')) {
            switch (json_last_error()) {
                case JSON_ERROR_NONE:
                    return $result;

                case JSON_ERROR_DEPTH:
                    throw new JSONException('json_decode - Maximum stack depth exceeded');

                case JSON_ERROR_CTRL_CHAR:
                    throw new JSONException('json_decode - Unexpected control character found');

                case JSON_ERROR_SYNTAX:
                    throw new JSONException('json_decode - Syntax error, malformed JSON');

                default:
                    throw new JSONException('Invalid JSON');
            }
        } elseif ($result === null) {
            throw new JSONException('Invalid JSON');
        }

        return $result;
    }
public static function decode($string, $returnArrays = false)
    {
        $result = json_decode($string, $returnArrays);

        if (function_exists('json_last_error')) {
            switch (json_last_error()) {
                case JSON_ERROR_NONE:
                    return $result;

                case JSON_ERROR_DEPTH:
                    throw new JSONException('json_decode - Maximum stack depth exceeded');

                case JSON_ERROR_CTRL_CHAR:
                    throw new JSONException('json_decode - Unexpected control character found');

                case JSON_ERROR_SYNTAX:
                    throw new JSONException('json_decode - Syntax error, malformed JSON');

                default:
                    throw new JSONException('Invalid JSON');
            }
        } elseif ($result === null) {
            throw new JSONException('Invalid JSON');
        }

        return $result;
    }
public static function decode ( $ string , $ returnArrays = false ) { $ result = json_decode ( $ string , $ returnArrays ) ; if ( function_exists ( 'json_last_error' ) ) { switch ( json_last_error ( ) ) { case JSON_ERROR_NONE : return $ result ; case JSON_ERROR_DEPTH : throw new JSONException ( 'json_decode - Maximum stack depth exceeded' ) ; case JSON_ERROR_CTRL_CHAR : throw new JSONException ( 'json_decode - Unexpected control character found' ) ; case JSON_ERROR_SYNTAX : throw new JSONException ( 'json_decode - Syntax error, malformed JSON' ) ; default : throw new JSONException ( 'Invalid JSON' ) ; } } elseif ( $ result === null ) { throw new JSONException ( 'Invalid JSON' ) ; } return $ result ; }
Performs a JSON decode of the string

@param string  $string       The json  string being decoded.
@param boolean $returnArrays When TRUE, returned objects will be converted into associative arrays.

@throws Exception When a json error occurs
@return mixed
Performs a JSON decode of the string