hiroto-k / json5-php
该包已被 弃用 并不再维护。未建议替代包。
PHP 的 JSON5 解析器
1.0.2
2016-07-03 03:56 UTC
Requires
- php: >=5.5.0
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ~4.8
This package is not auto-updated.
Last update: 2018-10-28 03:51:35 UTC
README
PHP 的 JSON5 解析器。此库以 kujirahand/JSON5-PHP 为参考。
要求
- PHP 5.5.11 或更高版本
- Composer
- JSON 扩展
- mbstring 扩展
功能
- 解析 JSON5 字符串
- 通过文件解析 JSON5
安装
使用 composer。
1, 下载此库
修改 composer.json
中的 require 指令。
{ "require": { "hiroto-k/json5-php": "~1.0" } }
2, 加载 vendor/autoload.php
文件
请在您的 PHP 文件中添加 require "vendor/autoload.php"
。
3, 使用 JSON5
类
示例
<?php require 'vendor/autoload.php'; use HirotoK\JSON5\JSON5; $json5_string = "{hoge: 'foo',}"; // Return 'stdClass' $json_object = JSON5::decode($json5_string); // Return 'array' $json_array = JSON5::decode($json5_string, true); $json5_file = './tests/files/example.json5'; // Pass file name or SplFileObject. // Return 'stdClass' $json_object = JSON5::decodeFile($json5_file); $json_object = JSON5::decodeFile(new SplFileObject($json5_file)); // Return 'array' $json_array = JSON5::decodeFile($json5_file, true); $json_array = JSON5::decodeFile(new SplFileObject($json5_file), true);