我有一个如下的json
[{
"name": "abc",
"Path": "i.abc",
"count": 5347,
"subFolders": []
},
{
"name": "cde",
"Path": "i.cde",
"count": 0,
"subFolders": [{
"name": "efg",
"Path": "",
"count": 0,
"subFolders": []
},
{
"name": "hij",
"Path": "i.hij",
"count": 1,
"subFolders": []
}]
}]
我想根据“路径”(其唯一)值更改“计数”值。例如,我想将路径“i.hij”的计数更改为 2。以下是我尝试过的代码。
var json = "above json";
for (i=0; i < json.length; i++) {
this.updateJson(json[i], path, count);
}
updateJson: function(json, path, count) {
if (json.path == path) {
json.count = count;
return json;
}
if (json.subFolders != null && json.subFolders.length > 0) {
for(j=0; j < json.subFolders.length; j++) {
this.updateJson(json.subFolders[j], path, count);
}
}
}
我如何获得具有修改值的整个 json?