简体   繁体   English

编辑本地 .json 文件

[英]edit local .json file

I am trying to edit .json file through my .js file that I created just next to it.我正在尝试通过我在它旁边创建的 .js 文件来编辑 .json 文件。 i am using ajax call to fetch the data from my .json file but for editing I dont know how to do that, here is my code for fetching data:我正在使用 ajax 调用从我的 .json 文件中获取数据,但为了进行编辑,我不知道该怎么做,这是我获取数据的代码:

 var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { objects =JSON.parse(xhttp.responseText) ; } }; xhttp.open("GET", "object.json", true); xhttp.send();

this is also my .json file:这也是我的 .json 文件:

 { "circles":[ { "id":1 , "cx":100, "cy":100, "r":50, "stroke":"green" , "strokeWidth":4, "fill":"yellow" }, { "id":2 , "cx":30, "cy":30, "r":10, "stroke":"green" , "strokeWidth":4, "fill":"yellow" } ] }

please give me a clue thank you guys :))请给我一个线索谢谢你们:))

You can fetch data from the server from the front-end, but to edit the data you need to create some backend functionality.您可以从前端从服务器获取数据,但要编辑数据,您需要创建一些后端功能。 This can be either a server or a serverless function, or a hosted db call, but you can't edit a plain .json file without a backend.这可以是服务器或无服务器函数,也可以是托管的 db 调用,但您无法在没有后端的情况下编辑纯 .json 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM