arturdoruch/json
Composer 安装命令:
composer require arturdoruch/json
包简介
JSON component
README 文档
README
- Wraps JSON decoding and encoding actions into class. Handles decoding error.
- Provides JSON syntax highlighting.
Installation
Install by running composer command composer require arturdoruch/json
Usage
Decode JSON
use ArturDoruch\Json\Json; use ArturDoruch\Json\UnexpectedJsonException; $jsonString = ''; // Decode JSON to array or stdClass object. // If JSON is invalid `ArturDoruch\Json\UnexpectedJsonException` is thrown. $json = new Json($jsonString); // Get decoded JSON. $json->getDecoded(); // Get encoded JSON with specified options like JSON_PRETTY_PRINT. $json->getEncoded(); // Catch decoding exception try { $json = new Json($jsonString); } catch (UnexpectedJsonException $exception) { // Get decoded invalid JSON. $exception->getJson(); // Get error code. $exception->getCode(); }
Highlight JSON syntax
use ArturDoruch\Json\JsonUtils; // JSON string. $json = '{"string": "foo bar \"baz\"", "integer": 128, "float": -1.5678, "boolean": true, "null": null}'; $classPrefix = 'json'; $highlighted = JsonUtils::highlightSyntax($json, $classPrefix);
Define the following CSS styles to styling JSON code:
- span.{classPrefix}-key {}
- span.{classPrefix}-string {}
- span.{classPrefix}-integer {}
- span.{classPrefix}-float {}
- span.{classPrefix}-boolean {}
- span.{classPrefix}-null {}
统计信息
- 总下载量: 27
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-07-02