markup / json
Json 包装器,提供更健壮的 Api(尽可能匹配 7.3)
0.1.3
2019-02-28 14:09 UTC
Requires
- php: ^7.1
Requires (Dev)
- phpstan/phpstan-shim: @stable
- phpunit/phpunit: ^7
- slevomat/coding-standard: @stable
- squizlabs/php_codesniffer: @stable
This package is auto-updated.
Last update: 2024-09-10 07:01:18 UTC
README
Json 包装器,提供更健壮的 API,与 PHP 7.3 匹配时使用异常而不是错误。
以下 json 选项始终使用
- JSON_UNESCAPED_UNICODE
- JSON_BIGINT_AS_STRING
- JSON_THROW_ON_ERROR
用法
try { $json = '{"a":1}'; $data = Encoder::decode($json); $json = Encoder::encode($data); } catch (\JsonException $exception) { echo $exception->getMessage(); // echoes "Syntax error" }
参考
- https://wiki.php.net/rfc/json_throw_on_error
- https://ayesh.me/Upgrade-PHP-7.3#json-exceptions
- https://github.com/php/php-src/blob/master/ext/json/json.c#L257