xoubaman / json
简单的 JSON 封装器
0.1
2020-05-16 17:07 UTC
Requires
- php: ^7.3
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^9.1
- roave/security-advisories: dev-master
This package is auto-updated.
Last update: 2024-09-17 03:26:45 UTC
README
简单的 JSON 封装类。
功能
- 编码数组|对象
- 解码 JSON 字符串
- 验证 JSON 字符串
- 失败时抛出异常
没有其他。正如所说,它是简单的。
用法
Json::encode($input): string
: 编码为 JSONJson::decode(string $json): array
: 将 JSON 解码为数组Json::fromString(string $json)
: 创建新的 Json 实例$json->isValid(): bool
: 提供的 JSON 是否有效$json->input(): string
: 实例化时使用的输入$json->error(): string
: 错误描述,如果没有错误则为空$json->errorCode(): int
: 错误代码,如果没有错误则为 JSON_ERROR_NONE$json->asArray(): array
: 解码的输入,如果不是有效的 JSON 则抛出RuntimeException