beste / json
一个简单的JSON助手,用于解码和编码JSON
1.5.0
2024-08-16 22:44 UTC
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0
- ext-json: *
Requires (Dev)
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^1.10
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/phpunit: ^10.4.2
- rector/rector: ^0.18.10
README
一个简单的助手,用于解码和编码JSON,包括从文件中。
使用方法
use Beste\Json; use UnexpectedValueException; $object = Json::decode('{"key": "value"}'); $array = Json::decode('{"key": "value"}', $forceArray = true); $object = Json::decodeFile('/path/to/file.json'); $json = Json::encode($object); $prettyJson = Json::pretty($object); // When something goes wring while decoding/encoding, // an `UnexpectedValueException` is thrown try { Json::decode('{]'); } catch (UnexpectedValueException $e) { // Handle error }
安装
composer require beste/json
运行测试
composer test