jannejava / json翻译 / 编辑

最近提交:5月前
创建时间:2018.05.11

语言构成

PHP100.0%

README

Wrap JSON encoding/decoding errors in exception

A simple wrapper around json_encode() and json_decode() for catching any errors without executing json_last_error().


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 http://php.net/manual/en/function.json-last-error.php#refsect1-function.json-last-error-returnvalues 
    echo $e->getMessage();
    echo $e->getCode();
}

Installation

You'll have to follow a couple of simple steps to install this package.

Downloading

Via composer:

$ composer require eastwest/json:^3.0

Or add the package to your development dependencies in composer.json and run composer update eastwest/json to download the package:

{
    "require": {
        "eastwest/json": "^3.0"
    }
}

讨论区

说说你的看法