lukaserat / webmozart-json-laravel
Laravel 的 webmozart/json 服务提供者
dev-master
2015-06-14 01:07 UTC
Requires
- illuminate/support: >=4.1
- webmozart/json: 1.0.0
Requires (Dev)
- phpunit/phpunit: ^5.0@dev
This package is auto-updated.
Last update: 2024-09-14 18:52:49 UTC
README
为webmozart/json提供Laravel 框架的包装器。
安装
使用 [Composer] 安装此包
$ composer require lukaserat/webmozart-json-laravel
Laravel 用户
我已经将 webmozart/json
提供的两个主要类 Encoder 和 Decoder 合并,以便于使用。
只需包含服务提供者即可。
// app/config/app.php
'providers' => [
'...',
'Lukaserat\WebmozartJson\JsonServiceProvider'
];
注意:外观将被自动注册为 'JsonHelper'
当此提供者启动时,您将可以访问来自 webmozart/json
的有用函数。请参见下面的示例
编码
而不是这样做...
// somewhere in your application..
use Webmozart\Json\JsonEncoder;
$encoder = new JsonEncoder();
// Store JSON in string
$string = $encoder->encode($data);
// Store JSON in file
$encoder->encodeFile($data, '/path/to/file.json');
您可以这样做...
// Store JSON in string
$string = JsonHelper::encode($data);
// Store JSON in file
JsonHelper::encodeFile($data, '/path/to/file.json');
Webmozart/Json 使用
这只是一个 Laravel 的包装器。有关 webmozart/json
的更多详细信息,请访问其 github 页面。