isaacongoma/jsonwriter

读取和写入PHP数组或Laravel Collection到JSON文件

dev-master 2022-06-14 08:39 UTC

This package is auto-updated.

Last update: 2024-09-05 14:38:07 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License Monthly Downloads Daily Downloads Laravel5.8

读取和写入PHP数组| Laravel Collection | EloquentCollection到json文件

安装

您可以通过composer安装此包

composer require manojkiran/jsonwriter

导入

use Manojkiran\JsonWriter\Facades\JsonWriter;

使用方法

写入

将内容写入Json

    //get the List of Active users
    $usersList      = User::where('status','=','Active')->get();
    //getting the path where the file is available
    $jsonFilePath   = storage_path('jsonWriter.json');
    //loading the Json File and Writing the Content to it
    $writeToJson    = JsonWriter::load( $jsonFilePath)
                        ->write($usersList);                

将内容写入Json(强制)

//by default the duplicate Content Will Not to Writtent To Json File(To Reduce the data Size)

    //array of the Projects by Taylor Otwell
    $laravel = ['name' => 'Taylor Otwell','developed' => ['Laravel','Lumen','Telescope','Nova']];
    //getting the path where the file is available
    $jsonFilePath   = storage_path('jsonWriter.json');
    //loading the Json File and Writing the Content to it
    $writeToJson    = JsonWriter::load( $jsonFilePath)
                        ->write($laravel,true);             

读取

    //get the List of Active users
    $usersList      = User::where('status','=','Active')->get();
    //getting the path where the file is available
    $jsonFilePath   = storage_path('jsonWriter.json');
    //loading the Json File and Writing the Content to it
    $writeToJson    = JsonWriter::load( $jsonFilePath)
                        ->parseFile();

测试

composer test

变更日志

请参阅 CHANGELOG 了解最近的变化。

贡献

请参阅 CONTRIBUTING 了解详细信息。

安全性

如果您发现任何安全相关的问题,请通过电子邮件 manojkiran10031998@gmail.com 而不是使用问题跟踪器来报告。

致谢

许可证

MIT许可证(MIT)。请参阅 许可证文件 了解更多信息。

Laravel包模板

此包使用 Laravel包模板 生成。