0
编辑本地JSON文件
请回答我,例如Select
代码如何使用JavaScript
- 我要值添加到阵列的本地文件JSON(插入成员JSON)
- 元素也取代了我的元素像
type
,name
...在JSON(在JSON更新部件) - 删除数行,其中
id="1"
和email="[email protected]"
(在JSON删除memebr)
JSON文件:report.json
var amir='{"reports":[' +
'{"id": "1","type": "admin","name": "amir","email": "[email protected]","password": "123"},' +
'{"id": "2","type": "member","name": "kevin","email": "[email protected]","password": "1234"}]}';
例如用于检查登记管理select
代码:
var obj = JSON.parse(amir);
for(c = 0; c <= obj.reports.length - 1; c++) {
type = obj.reports[c].type.toString();
if (type == "admin") {
active = 1;
}
if (c == obj.reports.length - 1) {
if (active == 1)
alert("Yes");
else
alert("No");
}
}
你怎么在代码中加入JSON文件?包括什么方法? – murrometz
浏览器中的Javascript没有权限编辑磁盘上的文件。 – Steve
没错。我认为你应该编写php文件来操纵你的json。 (使用json_decode,json_encode函数。)比用你的javascript说话(ajax-post,ajax-get等) – murrometz