# class2json **Repository Path**: vijay_0215/class2json ## Basic Information - **Project Name**: class2json - **Description**: 将PHP的类转换为json字符串 - **Primary Language**: PHP - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-11-28 - **Last Updated**: 2023-09-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # class2json ## 介绍 将PHP的类转换为json字符串 ## 安装教程 ```shell script composer require dreamcat/class2json ``` ## 使用说明 可以直接用编码器,如下所示 ```php ext = ["abc"]; $encoder = new Class2Json(); $json = $encoder->jsonEncode($data); echo $json; # 输出 [{"ext":["abc"]}] ``` 也可以用数据修正器得到可json序列化的数据,如下所示 ```php 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";}}} ```