otaavioo / json
用于json编码/解码功能的一个轻量级包
2.1.0
2024-04-26 14:44 UTC
Requires
- php: ^7.2
- ext-json: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.4
- phpunit/phpunit: ^6.0
- squizlabs/php_codesniffer: ^3.9
README
用于json编码/解码功能的一个轻量级包
安装
composer require otaavioo/json ^2.0
编码
// Instantiate the class $json = new Json(); $array = ['key' => 'value']; // And then, get encoded json echo $json->encode($array);
解码
// Instantiate the class $json = new Json(); $string = '{"key":"value"}'; // And then, get decoded json echo $json->decode($string); // And if you have a doubly encoded json, like this $string = '{\"key\":\"value\"}'; // The decode method will return the same object as before echo $json->decode($string);
有效
// Instantiate the class $json = new Json(); $string = '{"key":"value"}'; // And then, check if is valid echo $json->isValid($string);
开发
- 要安装依赖项,请运行
composer install
测试
- 您可以使用PHPUnit运行以下命令进行测试:
php vendor/bin/phpunit