定制 aalfiann/json-class-php 二次开发

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

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

aalfiann/json-class-php

Composer 安装命令:

composer require aalfiann/json-class-php

包简介

A class for handle json in a better way.

关键字:

README 文档

README

Version Total Downloads License

A class for handle json in a better way.

Installation

Install this package via Composer.

composer require "aalfiann/json-class-php:^1.0"

Usage

Encode

require_once ('vendor/autoload.php');
use \aalfiann\JSON;

$data = [
    'result'=>'just make a test!',
    'data' => [
        'id' => '1',
        'user' => 'your name',
        'email' => 'your_email@gmail.com',
        'website' => 'http://yourdomain.com',
        'non-utf8' => 'السلام علیکم ورحمة الله وبرکاته!'
    ]
];

header('Content-Type: application/json');
$json = new JSON;
echo $json->encode($data,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);

Decode

require_once ('vendor/autoload.php');
use \aalfiann\JSON;

$data = '{"result":"just make a test!","data":{"id":"1","user":"your name","email":"your_email@gmail.com","website":"http://yourdomain.com","non-utf8":"\u00d8\u00a7\u00d9\u0084\u00d8\u00b3\u00d9\u0084\u00d8\u00a7\u00d9\u0085 \u00d8\u00b9\u00d9\u0084\u00db\u008c\u00da\u00a9\u00d9\u0085 \u00d9\u0088\u00d8\u00b1\u00d8\u00ad\u00d9\u0085\u00d8\u00a9 \u00d8\u00a7\u00d9\u0084\u00d9\u0084\u00d9\u0087 \u00d9\u0088\u00d8\u00a8\u00d8\u00b1\u00da\u00a9\u00d8\u00a7\u00d8\u00aa\u00d9\u0087!"},"logger":{"timestamp":"2018-09-17 13:53:12","uniqid":"5b9f95a812c0f"}}';

$json = new JSON;
echo var_dump($json->decode($data,true));

Debug

You can easily debug with set property debug to true.

require_once ('vendor/autoload.php');
use \aalfiann\JSON;

header('Content-Type: application/json');
$json = new JSON;
$json->debug=true;
echo $json->encode($data,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);

Chain Usage Example

require_once ('vendor/autoload.php');
use \aalfiann\JSON;

header('Content-Type: application/json');
$json = new JSON;
echo $json->withSanitizer()->withLog()->encode(['user'=>'yourname'],JSON_PRETTY_PRINT);

Properties

  • $withlog=false,$sanitize=false,$ansii=false,$debug=false,$makesimple=false,$trim=false;

Chain Function

  • withSanitizer($sanitize=true) this will sanitize your data array before execute json_encode.
  • withTrim($trim=true) this will trimmed your data array or string before execute json_encode or json_decode.
  • withLog($withlog=true) this will append the logger data into your json.
  • setAnsii($ansii=true) this will make sanitizer works to handle ANSII chars.
  • setDebug($debug=true) this is for debugging purpose.
  • makeSimple($makesimple=true) this will hide the additional data in debug output.

Main Function

  • encode($data,$options=0,$depth=512) encode array or string to json format.
  • decode($json,$assoc=false,$depth=512,$options=0) decode json string to stdClass/array.
  • isValid($json=null) to determine json string is valid or not.

Helper Function

  • convertToUTF8($string) convert string to valid UTF8 chars.
  • convertToUTF8Ansii($string) convert string to valid UTF8 chars (support ANSII chars).
  • trimValue($string) trim the data array or string to strip the whitespace or any characters consider to blank value.
  • debug_encode($string,$options=0,$depth=512) debugger to test json encode.
  • debug_decode($json,$assoc=false,$depth=512,$options=0) debugger to test json decode.
  • errorMessage($jsonlasterror,$content) case error message about json.
  • fixControlChar($string) Most common fixed hidden control char in json string which made json decode fails.
  • modifyJsonStringInArray($data,$jsonfield,$setnewfield="") modify json data string in some field array to be nice json data structure.
  • concatenate($data,$escape=true,$options=0,$depth=512) concatenate json data
  • minify($json) Minify the json string

aalfiann/json-class-php 适用场景与选型建议

aalfiann/json-class-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 120 次下载、GitHub Stars 达 3, 最近一次更新时间为 2018 年 09 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「json」 「class」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 aalfiann/json-class-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 aalfiann/json-class-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 aalfiann/json-class-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-17