railt / json
此包已被废弃且不再维护。没有推荐替代包。
用于处理json数据的简单库
1.4.x-dev
2019-05-21 13:46 UTC
Requires
- php: >=7.1.3
- ext-json: *
- justinrainbow/json-schema: ~5.2
- phplrt/io: ~1.1
- phplrt/lexer: ~1.1
- phplrt/parser: ~1.1
Requires (Dev)
- phplrt/compiler: ~1.0
- phpunit/phpunit: ^7.5
Suggests
- railt/lexer: (1.4.*) JSON5 decoder support
- railt/parser: (1.4.*) JSON5 decoder support
This package is auto-updated.
Last update: 2020-06-21 16:36:57 UTC
README
Json
注意:所有问题和疑问请发送至 https://github.com/railt/railt/issues
JSON RFC-7159 使用
关于RFC-7159规范的简单示例。
编码
<?php use Railt\Json\Json; use Railt\Json\Exception\JsonException; try { $json = Json::encode([1, 2, 3]); } catch (JsonException $exception) { // Exception handling }
解码
<?php use Railt\Json\Json; use Railt\Json\Exception\JsonException; try { $data = Json::decode(<<<'JSON' { "quotes": "I can use \"double quotes\" here", "float": 0.8675309, "number": 42, "array": ["a", "b", "c"] } JSON ); } catch (JsonException $exception) { // Exception handling }
JSON5 使用
编码
<?php use Railt\Json\Json5; use Railt\Json\Exception\JsonException; try { $json = Json5::encode([1, 2, 3]); } catch (JsonException $exception) { // Exception handling }
解码
<?php use Railt\Json\Json5; use Railt\Json\Exception\JsonException; try { $data = Json5::decode(<<<'JSON5' // Simple example of JSON5 spec { unquoted: 'and you can quote me on that', singleQuotes: 'I can use "double quotes" here', lineBreaks: "Look, Mom! \ No \\n's!", hexadecimal: 0xDEADBEEF, leadingDecimalPoint: .42, andTrailing: 23., positiveSign: +1, trailingComma: 'in objects', andIn: ['arrays',], "backwardsCompatible": "with JSON", } JSON5 ); } catch (JsonException $exception) { // Exception handling }