library laravel-another-json
Yet Another JSON encoder for Laravel.
seekerliu/laravel-another-json
Yet Another JSON encoder for Laravel.
- Sunday, September 10, 2017
- by seekerliu
- Repository
- 3 Watchers
- 3 Stars
- 285 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 2 Forks
- 0 Open issues
- 1 Versions
- 62 % Grown
laravel-anothor-json
Yet Another JSON Encoder For Laravel.
用于修复 PHP7.1、7.2beta 中 json_encode() 处理 float/double 型数值时溢出的问题., (*1)
感谢博主提供的思路 http://www.itread01.com/articles/1489774743.html, (*2)
示例
```shell, (*3)
$a = 0.1 + 0.7
=> 0.8
printf('%.20f', $a)
=> 0.79999999999999993339
json_encode($a)
=> "0.7999999999999999"
\YaJson::encode($a)
=> "0.8"
```, (*4)
用法
-
修复精度并进行 json_encode :, (*5)
$data = [
'a' => 0.1 + 0.7,
'b' => ['string1', 'string2'],
];
\YaJson::encode($data); //"{"a":0.8,"b":["string1","string2"]}"
-
只获取修复后的数据,不进行 json_encode :, (*6)
$data = [
'a' => 0.1 + 0.7,
];
\YaJson::prepare($data); //['a'=>0.8]
安装
-
安装包文件, (*7)
composer require "seekerliu/laravel-another-json:dev-master"
配置
Laravel 5.5
Laravel 5.5 安装新包后会默认执行 @php artisan package:discover 命令,所以可以不进行下面的操作。, (*8)
-
注册 ServiceProvider 及 Facade:, (*9)
php artisan package:discover
-
如需修改默认循环深度、精度位数,则创建配置文件:, (*10)
php artisan vendor:publish
Laravel 5.4 及以下
-
注册 ServiceProvider 及 Facade:, (*11)
'providers' => [
//...
Seekerliu\YaJson\ServiceProvider::class,
],
'aliases' => [
//...
'YaJson' => Seekerliu\YaJson\Facade::class,
],
-
如需修改默认循环深度、精度位数,则创建配置文件:, (*12)
php artisan vendor:publish --provider="Seekerliu\YaJson\ServiceProvider"
License
MIT, (*13)
dev-master
9999999-dev
Yet Another JSON encoder for Laravel.
Sources
Download
MIT
by
seekerliu