Answered
How to transfer myparStn to n in myJSON.n = v;, changing it to myJSON.myparStn = v;
I want to reuse the rwJSON() function, but I don't know how to pass the name to "myJSON. n = v";
For example, I want to write data with a field (name is myParStn, value is 20) to my.json, but I found that rwJSON(myPar, v) cannot be implemented.
Here, n cannot be used as a parameter.
It can be used as a field name on its own.
rwJSON(myparStn,r);
function rwJSON(n,v) {
// read the json file's contents
var myJSON = readFile(pathToMyJSONFile);
if (!myJSON)
return alert('Could not read JSON file.');
// parse as json
myJSON = JSON.parse(myJSON);
// input text;
myJSON.n = v;
var f = writeFile(pathToMyJSONFile, JSON.stringify(myJSON, undefined, '\t'));
}
