1 | <?php |
||
10 | class JsonUtils |
||
11 | { |
||
12 | /** |
||
13 | * @var array JSON error messages |
||
14 | */ |
||
15 | protected static $errorMessages = [ |
||
16 | JSON_ERROR_NONE => 'No error has occurred', |
||
17 | JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded', |
||
18 | JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON', |
||
19 | JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded', |
||
20 | JSON_ERROR_SYNTAX => 'Syntax error', |
||
21 | JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded', |
||
22 | JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded', |
||
23 | JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded', |
||
24 | JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given', |
||
25 | ]; |
||
26 | |||
27 | /** |
||
28 | * Decode a JSON string into a php representation. |
||
29 | * |
||
30 | * @param string $json string to convert |
||
31 | * @param bool $assoc return as associative array |
||
32 | * @param int $options JSON options |
||
33 | * |
||
34 | * @throws \InvalidArgumentException |
||
35 | * @throws \RuntimeException |
||
36 | * |
||
37 | * @return mixed |
||
38 | */ |
||
39 | 4 | public static function decode($json, $assoc = false, $options = 0) |
|
51 | |||
52 | /** |
||
53 | * Encode a PHP value into a JSON representation. |
||
54 | * |
||
55 | * @param mixed $value |
||
56 | * @param int $options [optional] |
||
57 | * |
||
58 | * @throws \RuntimeException |
||
59 | * |
||
60 | * @return string |
||
61 | * |
||
62 | * @link http://php.net/manual/en/function.json-encode.php |
||
63 | */ |
||
64 | 1 | public static function encode($value, $options = 0) |
|
75 | } |
||
76 |