phphleb/nicejson

将 json 转换为可读形式

dev-main 2024-02-06 21:33 UTC

This package is auto-updated.

Last update: 2024-09-06 22:41:40 UTC


README

HLEB1 HLEB2 PHP License: MIT

小于 8.2 版本的 PHP 之前的代码

将 json 转换为可读形式

使用 Composer 安装

composer require phphleb/nicejson

转换

{"example":["first","second"]}

{
   "example": [
       "first",
       "second"
   ]
}
$data = '{"example":["first","second"]}'; // string json
file_put_contents('/path/to/result/json/file/', (new \Phphleb\Nicejson\JsonConverter())->get($data));

$data = ["example"=>["first","second"]]; // array
file_put_contents('/path/to/result/json/file/', (new \Phphleb\Nicejson\JsonConverter())->get($data));

$data = (object) ["example"=>["first","second"]]; // object
file_put_contents('/path/to/result/json/file/', (new \Phphleb\Nicejson\JsonConverter())->get($data));

向 json_encode(...) 添加标志

use Phphleb\Nicejson\JsonConverter;
$jsonConverterObject = new JsonConverter(JSON_FORCE_OBJECT);