plumphp/plum-json
最新稳定版本:v0.3
Composer 安装命令:
composer require plumphp/plum-json
包简介
README 文档
README
PlumJsons includes readers, writers and converters for JSON strings and files. Plum is a data processing pipeline for PHP.
Developed by Florian Eckerstorfer in Vienna, Europe.
Features
Readers
JsonFileReaderreads a.jsonfile from disk and decodes itJsonReaderdecodes a JSON string
Writers
JsonFileWriterencodes an object/array into JSON and saves it to diskJsonWriterencodes an object/array into JSON and returns the string
Converters
JsonDecodeConvertertakes a JSON string and decodes itJsonEncodeConvertertakes an object/array and encodes it to JSON
Installation
You can install Plum using Composer.
$ composer require plumphp/plum-json
Usage
Please refer to the Plum documentation for more information about Plum in general.
JsonReader
Plum\PlumJson\JsonReader reads a JSON string. If you want to read a .json file checkout
JsonFileReader.
use Plum\PlumJson\JsonReader; $reader = new JsonReader('[{'key1': 'value1', 'key2': 'value2'}]'); $reader->getIterator(); // -> \ArrayIterator $reader->count();
JsonFileReader
Plum\PlumJson\JsonFileReader reads a .json file.
use Plum\PlumJson\JsonFileReader; $reader = new JsonFileReader('foo.json'); $reader->getIterator(); // -> \ArrayIterator $reader->count();
JsonFileWriter
Plum\PlumJson\JsonFileWriter writes the items as JSON into a file.
use Plum\PlumJson\JsonFileWriter; $writer = new JsonFileWriter('foobar.json'); $writer->writeItem(['key1' => 'value1', 'key2' => 'value2')); $writer->finish();
It is essential that finish() is called, because there happens the actual writing. The prepare() method does
nothing.
JsonWriter
Plum\PlumJson\JsonWriter converts the items into JSON format. Please checkout JsonFileWriter if you
want to write the JSON into a file.
use Plum\PlumJson\JsonWriter; $writer = new JsonWriter(); $writer->writeItem(['key1' => 'value1', 'key2' => 'value2')); echo $writer->getJson(); // [{'key1': 'value1', 'key2': 'value2'}]
JsonDecodeConverter
Plum\PlumJson\JsonDecodeConverter uses Braincrafted\Json to decode JSON.
use Plum\PlumJson\JsonDecodeConverter; use Braincrafted\Json\Json; $converter = new JsonDecodeConverter(Json::DECODE_ASSOC); $converter->convert('{"foo": "bar"}'); // -> ['foo' => 'bar']
JsonEncodeConverter
Plum\PlumJson\JsonEncodeConverter uses Braincrafted\Json to encode an object
into JSON.
use Plum\PlumJson\JsonEncodeConverter; $converter = new JsonEncodeConverter(); $converter->convert(['foo' => 'bar']); // -> '{"foo": "bar"}'
Change Log
Version 0.3 (7 May 2015)
- Add
JsonDecodeConverter - Add
JsonEncodeConverter
Version 0.2 (22 April 2015)
- Add support for ReaderFactory
Version 0.1 (17 February 2015)
- Initial release
License
The MIT license applies to plumphp/plum- json. For the full copyright and license information, please view the LICENSE file distributed with this source code.
统计信息
- 总下载量: 40
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2015-02-11