kapitanluffy / json-object
将 JSON 作为对象在 PHP 中处理
dev-master
2018-04-26 04:01 UTC
Requires
- php: ^5.4
This package is auto-updated.
Last update: 2024-09-07 00:02:12 UTC
README
在 PHP 中将 JSON 作为对象处理,而不是字符串。
安装
composer require kapitanluffy/json-object
用法
$json = new JsonObject($data); // encoding to json $encoded = json_encode($json); $encoded = $json->encode(); $encoded = (string) $json; // decoding to data $decoded = JsonObject::decode($json); // set options $json->options(JSON_NUMERIC_CHECK)->encode(); // throw a JsonException on error $json->withErrors(true)->encode(); // check if the current instance throws an error $json->isErrorThrown(); // returns the last occurred JsonException JsonObject::getError();
请注意,方法 options 和 withErrors 返回一个新实例,而不是修改当前 JsonObject 实例。