16 private $jsonErrorMessages = [
17 JSON_ERROR_DEPTH =>
'Maximum depth exceeded',
18 JSON_ERROR_STATE_MISMATCH =>
'State mismatch',
19 JSON_ERROR_CTRL_CHAR =>
'Unexpected control character found',
20 JSON_ERROR_SYNTAX =>
'Syntax error, invalid JSON',
32 $ret = json_encode(
$data);
33 $this->checkJsonError(
$data);
49 $ret = json_decode(
$data, $asArray);
50 $this->checkJsonError(
$data);
61 private function checkJsonError()
63 $jsonError = json_last_error();
64 if ($jsonError !== JSON_ERROR_NONE) {
67 if (isset($this->jsonErrorMessages[$jsonError])) {
68 $message = $this->jsonErrorMessages[$jsonError];
72 'JSON Encoding / Decoding error: ' .
$message . var_export(func_get_arg(0),
true),
jsonDecode($data, $asArray=true)