承接 sgmendez/json 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sgmendez/json

最新稳定版本:v1.0.5

Composer 安装命令:

composer require sgmendez/json

包简介

A PHP library for manipulate JSON data

README 文档

README

License SensioLabsInsight Latest Stable Version Total Downloads Latest Unstable Version

Introduction

This PHP library create a wrapper for json_encode and json_decode PHP functions that normalize use across de PHP versions and throw exceptions when encoding or decoding fail.

Requirements

This library require PHP 5.3.3 or higher

Installation

You can use Composer to use this library in your application.

If you don't have Composer yet, download it following the instructions on http://getcomposer.org/ or just run the following command:

curl -s http://getcomposer.org/installer | php

And then execute this command to add libary to your project:

$ composer require sgmendez/json

Or require sgmendez/json into your composer.json file:

json
{
    "require": {
        "sgmendez/json": "*"
    }
}

Tests

You can run the PHPUnit tests, in directory test execute:

$ php phpunit.phar .

In this directory there are a copy of phpunit.phar for execution test

Examples

Encode JSON data:

php
use Sgmendez\Json\Json;

$json = new Json();

try
{
    $arrayData = array('foo' => 'Foo', 'bar' => 'Bar');
    $jsonData = $json->encode($arrayData);
} 
catch (Exception $ex) 
{
    echo '[EXCEPTION] MSG: '.$ex->getMessage().' | FILE: '.$ex->getFile().': '.$ex->getLine()."\n";
}

Decode JSON string (by default, return array data):

php
use Sgmendez\Json\Json;

$json = new Json();

try
{
    $jsonData = '{"foo":"Foo","bar":"Bar"}';
    $dataArray = $json->decode($jsonData);
} 
catch (Exception $ex) 
{
    echo '[EXCEPTION] MSG: '.$ex->getMessage() .
         ' | FILE: '.$ex->getFile().': '.$ex->getLine()."\n";
}


Decode JSON file (by default, return array data):

php
use Sgmendez\Json\Json;

$json = new Json();

try
{
    $dataArray = $json->decodeFile('/path/to/file.json');
} 
catch (Exception $ex) 
{
    echo '[EXCEPTION] MSG: '.$ex->getMessage() .
         ' | FILE: '.$ex->getFile().': '.$ex->getLine()."\n";
}

If you need to check if is valid json data, you can to use checkValidJsonData() method.

License

Licensed under the BSD License:

http://opensource.org/licenses/bsd-license.php

统计信息

  • 总下载量: 77
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-2-Clause
  • 更新时间: 2015-03-18