1 Star 0 Fork 0

Vijay / class2json

Create your Gitee Account
Explore and code with more than 8 million developers,Free private repositories !:)
Sign up
Clone or Download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

class2json

介绍

将PHP的类转换为json字符串

安装教程

composer require dreamcat/class2json

使用说明

可以直接用编码器,如下所示

<?php
use Dreamcat\Class2Array\Impl\Class2Json;

$data = [new \stdClass()];
$data[0]->ext = ["abc"];
$encoder = new Class2Json();
$json = $encoder->jsonEncode($data);
echo $json; # 输出 [{"ext":["abc"]}]

也可以用数据修正器得到可json序列化的数据,如下所示

<?php
use Dreamcat\Class2Array\Impl\DefaultJsonValueFixer;

$data = [new \stdClass()];
$data[0]->ext = ["abc"];
$fixer = new DefaultJsonValueFixer();
$fixed = $fixer->fixValue($data);
echo serialize($fixed);
# 输出 a:1:{i:0;a:1:{s:3:"ext";a:1:{i:0;s:3:"abc";}}}

Repository Comments ( 0 )

Sign in to post a comment

About

将PHP的类转换为json字符串 expand collapse
PHP
MIT
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
PHP
1
https://gitee.com/vijay_0215/class2json.git
git@gitee.com:vijay_0215/class2json.git
vijay_0215
class2json
class2json
master

Search