kelunik / streaming-json
Amp 的流式 JSON 解析器。
v1.0.0
2017-07-10 10:01 UTC
Requires
- amphp/amp: ^2
- amphp/byte-stream: ^1
- amphp/socket: ^0.10
- daverandom/exceptional-json: ^1.0.1
Requires (Dev)
- amphp/artax: ^3
- amphp/phpunit-util: ^1
- friendsofphp/php-cs-fixer: ^2.3
This package is auto-updated.
Last update: 2024-09-15 07:20:43 UTC
README
Amp 的流式 JSON 解析器。
安装
composer require kelunik/streaming-json
使用
$parser = new StreamingJsonParser($inputStream); while (yield $parser->advance()) { $parsedItem = $parser->getCurrent(); }
选项可以像对 json_decode
一样传递给构造函数。解析器将消耗传入的输入流,并且自身也是一个 Amp\Iterator
,允许消耗所有解析项目。任何格式不正确的消息都将使解析器失败。如果输入流结束,解析器将尝试解析最后一个项目,并成功或失败地完成迭代器,具体取决于最后一个项目是否格式不正确。