eastwest / json
将 JSON 编码/解码错误封装在异常中
v3.0.1
2018-06-14 10:10 UTC
Requires
- php: >=7.0
Requires (Dev)
- phpunit/phpunit: ^7.2
This package is auto-updated.
Last update: 2024-09-07 07:58:00 UTC
README
捕获 json_encode()
和 json_decode()
错误而不执行 json_last_error()
。在 PHP 7.3 中,这些函数将 抛出异常。
use Eastwest\Json\Json; use Eastwest\Json\JsonException; try { $json = Json::encode(['key' => 'value']); } catch (JsonException $e) { // code and message will match json_last_error() values: // @link https://php.ac.cn/manual/en/function.json-last-error.php#refsect1-function.json-last-error-returnvalues echo $e->getMessage(); echo $e->getCode(); }
安装
您需要遵循几个简单的步骤来安装此包。
下载
通过 Composer
$ composer require eastwest/json:^3.0
或者在 composer.json
中添加此包到您的开发依赖项,并运行 composer update eastwest/json
来下载包
{ "require": { "eastwest/json": "^3.0" } }
如果您需要一种部署文件或管理 Laravel Forge 服务器的方法,请查看 GitFTP-Deploy 或 F-Bar