定制 gries/json-resolver 二次开发

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

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

gries/json-resolver

Composer 安装命令:

composer require gries/json-resolver

包简介

A simple tool to resolve objects / trees of objects when encoding / decoding json

关键字:

README 文档

README

JsonResolver is a simple class that enables you to recursively encode / decode a tree of objects to json without having to deal with stdClasses.

This is being achieved by simply injecting the original class into the json as "json_resolve_class" property.

Installation

JsonResolver can be installed via. composer:

{
    "require": {
        "gries/json-resolver": "dev-master"
    },
}

Usage

Every plain php object is supported the only requirement is that \JsonSerializeable is implemented.

Current features:

  • automatically decodes objects back to their previous classes.
  • automatically decodes related objects back to their previous classes if they implement the \JsonSerializeable interface.
  • automatically decodes arrays / traversable related objects if their values implement the \JsonSerializeable interface.
  • has a fallback method for objects that have not been previously encoded with the JsonResolver

example usage

<?php

$book = new Book(); // JsonSerializeable
$author = new Author(); // JsonSerializeable
$author->addBook($book);    // author has a property books that is a array or TraversableInterface

$resolver = new JsonResolver();

$json = $resolver->encode($author);
$author = $resolver->decode($json);

get_class($author); // Author
get_class($author->getBooks()->getFirst()); // Book

For further examples see the examples section.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-05-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固