bzick/jsonor

JSON的有用容器。使用JSON作为数组

1.0.1 2016-08-15 18:55 UTC

This package is auto-updated.

Last update: 2024-08-29 04:05:38 UTC


README

Build Status

用法

use Jsonor\JSON;

    
// returns null if it's valid json, or a ParsingException object.
JSON::lint($json);

// Call getMessage() on the exception object to get
// a well formatted error message error like this

// Parse error on line 2:
// ... "key": "value"    "numbers": [1, 2, 3]
// ----------------------^
// Expected one of: 'EOF', '}', ':', ',', ']'

// Call getDetails() on the exception to get more info.

// returns parsed json, like json_decode() does
$data = JSON::decode($json);
// sets yours callback on changes
$data->onChange(function () {
    // store in DB, e.g.
});
// Use $data as array
$data["d"][1]["name"] = "Banana";
$data["d"][1]["desc"] = "It's fruit";
$data["d"][] = [
    "name" => "Apple"
];

unset($c["d"][1]);

foreach($data as $key => $value) {
    // ...
}

安装

使用Composer快速安装

$ composer require bzick/jsonor

如果你有PSR-4自动加载器,Jsonor可以轻松地在另一个应用程序中使用,或者可以通过Composer安装作为CLI工具使用。

要求

  • PHP 5.4+
  • [可选] 使用PHPUnit 3.5+执行测试套件(phpunit --version)

提交错误和功能请求

错误和功能请求在GitHub上跟踪

作者

Ivan Shalganov - a.cobest@gmail.com

许可

Jsonor遵循MIT许可证 - 详细内容请参阅LICENSE文件