codedgr / json
JSON辅助库
1.0.1
2018-05-26 14:53 UTC
Requires
- php: >=7.1.0
Requires (Dev)
- phpunit/phpunit: ^7
This package is auto-updated.
Last update: 2024-09-14 18:47:47 UTC
README
此库每次json编码/解码操作失败时都会抛出异常。
安装
使用Composer
"require": {
"codedgr/json": "~1.0"
}
用法
定义一个数组
$array = [
'first-element' => 'this value',
'second-element' => [0,1,2,3,4],
];
然后使用try/catch包围的encode和decode函数
try{
$encodedJSON = JSON::encode($array);
$object = JSON::decode($encodedJSON);
}catch (JSONException $e){
echo $e->getMessage();
}
要求
- PHP 7.1或更高版本