estaheri/json
最新稳定版本:v1.1.3
Composer 安装命令:
composer require estaheri/json
包简介
An easy way for using json encoded strings in php
README 文档
README
An easy way for using json encoded strings in php.
Install
- Composer :
composer require estaheri/json - manually : Download it from release page of github and require the class file
json.phpin your code.
Examples
<?php // validate is a string json $is_json = json::_is($string); // json decode or encode string $json_decode = json::_in($json_string); $json_encode = json::_out($data); // get or update a key/keys from a json string $json_string = json::update($json_string,['firstName'=>'Will','lastName'=>'Smith']); $first_name = json::get($json_string,'firstName'); $name = json::get($json_string,['firstName','lastName']); // remove a key/keys from a json string $json_string = json::remove($json_string,'firstName'); $json_string = json::remove($json_string,['lastName','age']); // convert array or object or json string to these three types $array = json::to_array($data); $json = json::to_json($data); $object = json::to_object($data);
Questions :
Why should we use this class while php has json methods in it?
I just wrote this class for making codes more clean and shorter.
For example :
<?php $json_string='{"id": "1","firstName": "Tom","lastName": "Cruise"}'; #################################################### // using php itself // update a key from json string $decoded=json_decode($json_string); $decoded->firstName='Will'; $decoded->lastName='Smith'; $json_string = json_encode($decoded); #################################################### // using this library // update a key from json string $json_string = json::update($json_string,['firstName'=>'Will','lastName'=>'Smith']);
By the way I wrote it for self use but I think that maybe someone need it!
Where is the document?
All methods have a phpDoc document so there is no need to write a document for now.
- Also it's just class with simple methods!
统计信息
- 总下载量: 190
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-12-25