dnonov/json-parser 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

dnonov/json-parser

最新稳定版本:v1.0.2

Composer 安装命令:

composer require dnonov/json-parser

包简介

Thin wrapper around `json_decode` and `json_encode` with exceptions and some handy methods.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status

About

Thin wrapper around json_decode and json_encode with exceptions and some handy methods.

Requirements

PHP 7.4^

Installation

You can install the package via composer:

composer require dnonov/json-parser

Description

This mainly exists because of the silent json_decode; if something's wrong it will return null. I prefer exceptions and nicer method names. It is very thin wrapper around three functions in PHP standard library, but I'm tired of re-writing it every time.

Here's how to use it

use Dnonov\JsonParser\Facades\JSONParser;

$arrayData = JSONParser::decodeToArray("[{"one": 1, "two": 2}]");
$objectData = JSONParser::decodeToObject("[{"one": 1, "two": 2}]");

$array = ["one" => 1, "two" => 2];
$encodedArrayData = JSONParser::encode($array);

// Make sure file path is relative to `base_path()`.
$arrayFileData = JSONParser::decodeFromFileToArray("./data.json");
$objectFileData = JSONParser::decodeFromFileToObject("./data.json");

// There are some handy methods.
$object = JSONParser::arrayToObject(["one" => 1, "two" => 2]);
$array = JSONParser::objectToArray($object);

Various exceptions might be thrown during decoding and encoding.

  • JsonMaxDepthException
  • JsonInvalidOrMalformedException
  • JsonControlCharacterException
  • JsonSyntaxErrorException
  • JsonMalformedUTF8Exception
  • JsonRecursiveReferenceException
  • JsonInfinityOrNanDetectedException
  • JsonUnsupportedTypeException
  • JsonException
  • InvalidArgumentExceptions

Here's documentation on the equivalent errors in PHP Doc

Contributing

Bug reports and pull requests are always welcome.

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-02