承接 hampel/json 相关项目开发

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

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

hampel/json

最新稳定版本:2.4.1

Composer 安装命令:

composer require hampel/json

包简介

A simple wrapper for json_encode and json_decode with exception based error handling

关键字:

README 文档

README

Latest Version on Packagist Total Downloads Open Issues License

A simple wrapper for json_encode and json_decode with exception based error handling

By Simon Hampel

Note: as of PHP v7.3 there is now a JSON_THROW_ON_ERROR option for both native commands which should effectively render this package obsolete.

Installation

To install using composer, run the following command:

composer require hampel/json

Note that there are three versions of this package, depending on the version of PHP you use:

  • v2.1 supports PHP >= v5.3.3
  • v2.2 supports PHP >= v5.4.0
  • v2.3 supports PHP >= v5.5.0

The three versions will be maintained in parallel

Usage

All parameters are the same as specified for the PHP functions json_encode and json_decode respectively.

The main difference that this class provides is that it throws exceptions when there are errors and translates the error codes into meaningful text for you automatically.

<?php use Hampel\Json\Json; use Hampel\Json\JsonException; $data = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5); // Encode a variable as JSON: echo Json::encode($data); // Encode options $options = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP; echo Json::encode($data, $options); // Decode JSON: print_r(Json::decode('{"a":1,"b":2,"c":3,"d":4,"e":5}')); // Error handling try { Json::decode('{"a":1,"b":2,"c":3,"d":4,"e":5'); // missing } } catch (JsonException $e) { echo "Oops: " . $e->getMessage(); }

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固