dsjojts9734 2016-08-02 20:45
浏览 207

使用laravel修改json文件

as I can modify a json in laravel file? In the methods available for the File class, only allows me to add additional text:

File::append($path, $data);

however, can not find a method to modify.

example:

public function json(){
      $data = json_encode([
         'data1' => 'hello',
          'data2' => 'world' ]);
  File::append($path, $data);
}

public function ModifyJson(){

//how change value for data2?  

}

thank you very much for the help :)

  • 写回答

1条回答 默认 最新

  • doumanju2533 2016-08-02 21:42
    关注

    Use $data = json_decode($your_file_content,true), then modify $data as normal php array, and before save use json_encode($data) and save data.

    评论

报告相同问题?

悬赏问题

  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用