读取JSON文件,更新值并保存修改 [英] Read JSON file, update value and save modification

查看:1238
本文介绍了读取JSON文件,更新值并保存修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含此文字的JSON文件:

I have a JSON file containing this text:

[
  {
    "key" : "test1",
    "desc": "desc1"
  },
  {
    "key" : "test2",
    "desc": "desc2"
  },
]

我做了一个代码来读取这个文件的内容(使用AJAX)并将内容显示到HTML表格中。

I made a code to read the content of this file (using AJAX) and to display the content into an HTML table.

现在,我希望能够更新HTML数组中的值并保存对JSON文件的修改。

是否可以在JavaScript中使用?

Is it possible in JavaScript?

推荐答案

您需要一种服务器端技术来修改文件内容。如果你使用PHP就像读取文件一样简单,转换为数组并修改你需要的值,然后返回json解码值再次写入文件。

You need a server-side technology to modify file contents. If you use PHP is as simple as read file, transform to an array and modify the value that you need, and then return the json decode value to write the file again.

如果你只使用javascript,也许你需要使用Node.js作为服务器端解决方案。

If you use only javascript, maybe you need to use Node.js as server-side solution.

这篇关于读取JSON文件,更新值并保存修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆