如何用JavaScript读写外部本地JSON文件



我有一个JSON文件,我可以更改"src";以及";组成";但是我不能改变actions/postrender/sec输出值的值。

我正在使用这个js

file.template.src = "value1";
file.template.composition= "value2";
file.actions.postrender.output= "value3";
{
"template": {
"src": "value1",
"composition": "value2"
},
"actions": {
"postrender": [
{
"module": "@nexrender/action-encode",
"preset": "mp4",
"output": "encoded.mp4"
},
{
"module": "@nexrender/action-copy",
"input": "encoded.mp4",
"output": "d:/mydocuments/results/myresult.mp4"
}
]
}
}

file.actions.postrender.output= "value3";不工作,因为postrender是一个数组。

您需要指定要修改的元素(第一个元素为0,第二个元素为1(:

file.actions.postrender[0].output= "value3";
file.actions.postrender[1].output= "value3";

这是因为您没有选择数组中的第二个元素。使用索引运算符首先获取第二个元素,然后修改值:

file.actions.postrender[1].output= "value3";

这是因为键的te值"后渲染";是一个数组。

为了更新密钥";输出";对于数组的元素,您应该选择哪个元素,例如:

file.actions.postrender[0].output= "value3";

如果要更新所有元素,可以使用for循环。

最新更新