项目作者: DavidFricker

项目描述 :
A simple wrapper around PHP's Json functions giving a simple approach to error checking on decode.
高级语言: PHP
项目地址: git://github.com/DavidFricker/CleanJson.git
创建时间: 2016-05-08T20:00:08Z
项目社区:https://github.com/DavidFricker/CleanJson

开源协议:MIT License

下载


CleanJson

A simple wrapper around PHP’s JSON functions giving a simple approach to error checking on decode.

Example

All methods are static so an example useage would be as follows:

  1. <?php
  2. if(Json::decode("{}", false) === false)
  3. {
  4. // string does not contain valid JSON data.
  5. echo Json::get_error_message();
  6. }
  7. ?>

Why

This class is a simple wrapper around PHP’s JSON functions. It aims to make error detection and parsing simpler than it currently is.
For example the decode method decodes a JSON string and returns the resulting object/array. If the decode operation fails the wrapper function will return FALSE, unlike the default implementation which returns NULL.
The issue here being that a valid JSON string can be decoded and result in NULL also. This is not always desireable.

License

Released under the MIT license.