otaavioo/json

用于json编码/解码功能的一个轻量级包

2.1.0 2024-04-26 14:44 UTC

This package is auto-updated.

Last update: 2024-09-26 17:46:56 UTC


README

Build Coverage Status

用于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