braincrafted / json
此包已被废弃,不再维护。未建议替换包。
v0.3
2014-11-18 18:02 UTC
Requires (Dev)
- phpunit/phpunit: 3.7.x
README
json_encode() 和 json_decode() 的面向对象包装器,具有错误处理功能。
由欧洲维也纳的 Florian Eckerstorfer 开发。
安装
推荐通过 Composer 安装 BraincraftedJson。
$ composer require braincrafted/json:@stable
提示:您应将 @stable
替换为从 发布页面 获取的最新版本。
使用方法
use Braincrafted\Json\Json; use Braincrafted\Json\JsonDecodeException; // Encode a variable as JSON: echo Json::encode(array('name' => 'Bilbo Baggins')); // Decode JSON: print_r(Json::decode('{"name": "Bilbo Baggins"}')); // Decode JSON into an array: print_r(Json::decode('{"name": "Bilbo Baggins"}', Json::DECODE_ASSOC)); // Error handling try { Json::decode('{"name": "Bilbo Baggins"'); // missing } } catch (JsonDecodeException $e) { echo sprintf("Could not decode JSON.\nReason: %s", $e->getMessage()); }
变更日志
版本 0.3 (2014年11月18日)
- 从 PSR-0 切换到 PSR-4
- 将
Json::DECODE_ASSOC
和Json::DECODE_OBJECT
作为Json::decode()
的第二个参数使用
版本 0.2 (2013年11月15日)
- 将命名空间更改为
Braincrafted
许可证
The MIT License (MIT)
Copyright (c) 2013 Florian Eckerstorfer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.