alexkratky / variable-to-json
将任何变量或对象转换为JSON。
v1.0.0
2020-05-14 09:19 UTC
Requires
- php: >=7.0
This package is auto-updated.
Last update: 2024-09-12 17:02:23 UTC
README
将任何变量或对象转换为JSON。
安装
composer require alexkratky/variable-to-json
使用
require 'vendor/autoload.php'; use AlexKratky\VariableToJson; $x = new TestClass(); // test class $x->load(); $x->load2(); $x->load3(); file_put_contents("output.json", VariableToJson::convert($x, true)); file_put_contents("output2.json", VariableToJson::convert([ 'test' => 1 ], true)); file_put_contents("output3.json", VariableToJson::convert(function(string $text ="xx") { echo $text; }, true));
自定义选项
setDepth($maxDepth = 5)
- 设置对象扫描的最大深度setLength($maxLength = 300)
- 设置最大字符串长度