简体   繁体   English

更新JSON键值-AngularJS

[英]Update JSON key value - AngularJS

If I have a JSON file that contains a key, "text", and has an empty value how can I update the empty value? 如果我有一个包含密钥“ text”且值为空的JSON文件,如何更新该空值?

I am using angularjs to make it interact with the user. 我正在使用angularjs使其与用户交互。 I am also using $http.get to retrieve the json file. 我还使用$ http.get来检索json文件。 I am able to save the text to localstorage but I am having trouble sending the localstorage value into the JSON file. 我能够将文本保存到localstorage,但是我无法将localstorage值发送到JSON文件中。 Overall I want the user to refresh the page and the text to still be there. 总的来说,我希望用户刷新页面,并且文本仍然存在。

This is just a general overview of what I want to do which is why I am not providing code. 这只是我想要做的一般概述,这就是为什么我不提供代码的原因。 All I want to do is figure out how, if possible, to update the JSON file so that next time it is refreshed and the $http.get is called again, the key has an updated value and it is displayed. 我要做的就是弄清楚如何更新JSON文件,以便下次刷新该文件并再次调用$ http.get时,该键具有更新后的值并显示出来。

The basic step is to write a server side script (in perl/python/php etc) and then do an http post request from your AngularJS and your script updates the file in question. 基本步骤是编写服务器端脚本(在perl / python / php等中),然后从AngularJS发出http发布请求,然后脚本会更新相关文件。 This is a good link to understand how to do it in python http://www.pythonschool.net/server-side-scripting/introduction-to-server-side-scripting/ 这是了解如何在python中进行操作的好链接http://www.pythonschool.net/server-side-scripting/introduction-to-server-side-scripting/

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

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