RestContext::decodeJson PHP Method

decodeJson() protected method

Decode JSON string.
See also: http://www.php.net/json_last_error
protected decodeJson ( string $string ) : mixed
$string string A JSON string.
return mixed
    protected function decodeJson($string)
    {
        $json = json_decode($string, $this->associative);
        switch (json_last_error()) {
            case JSON_ERROR_NONE:
                return $json;
                break;
            case JSON_ERROR_DEPTH:
                $message = 'Maximum stack depth exceeded';
                break;
            case JSON_ERROR_STATE_MISMATCH:
                $message = 'Underflow or the modes mismatch';
                break;
            case JSON_ERROR_CTRL_CHAR:
                $message = 'Unexpected control character found';
                break;
            case JSON_ERROR_SYNTAX:
                $message = 'Syntax error, malformed JSON';
                break;
            case JSON_ERROR_UTF8:
                $message = 'Malformed UTF-8 characters, possibly incorrectly encoded';
                break;
            default:
                $message = 'Unknown error';
                break;
        }
        throw new \Exception('JSON decoding error: ' . $message);
    }