定制 yadakhov/json 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

yadakhov/json

最新稳定版本:v2.0.1

Composer 安装命令:

composer require yadakhov/json

包简介

A simple wrapper class to work with json in PHP.

关键字:

README 文档

README

Latest Stable Version License Build Status

A simple wrapper class for working with Json.

Work with json as an object in PHP. Provides a simple api with dot notation for field access.

Use get() or set() to access any fields in the json structure.

require __DIR__.'/vendor/autoload.php';
use Yadakhov\Json;

$json = new Json(['status' => 'success', 'developer' => ['name' => 'Yada Khov']]);
echo $json;  // {"status":"success","developer":{"name":"Yada Khov"}}

$json->set('status', 'winning');
echo $json;  // {"status":"winning","developer":{"name":"Yada Khov"}}

Installation

With Composer

$ composer require yadakhov/json

Old fashion php

// download src/Json.php to your code folder..
require_once '/path/to/Json.php';

use Yadakhov/Json;

$json = new Json();

Usage: The Constructor

Will to accept array or json encoded string.

// There are 2 ways to instantiation a new Json object

// 1.
$json1 = new Json('{"status":"success"}');

// 2
$json2 = new Json(['status' => 'success']);

API functions

$json->get('dot.notation') - get a field
$json->set('dot.notation', $value) - set a field
$json->toString() - return the Json object as a string
$json->toStringDot() - return the dot notation of the structure.
$json->toStringPretty() - json pretty print
$json->toArray() - return the array representation.

Design decision

Internally, the json is stored as a PHP array. This allows us to use dot notation.

The left hand side of a json encoded string needs to be double quoted.

{
    "status": "success"
}

Dependencies

PHP 5.4 for short array syntax.

This package uses illuminate/support for the array and string helpers.

Run tests

./vendor/bin/phpunit 

统计信息

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

GitHub 信息

  • Stars: 16
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-06-07