如何更改json中特定嵌套数组的值



我有下面的。json文件,我只是想根据用户输入改变向下和向上的值。

"android": {
"appium:autoAcceptAlerts": true,
"appium:automationName": "UiAutomator2",
"appium:newCommandTimeout": 180,
"appium:appPackage": "com.android.settings",
"appium:platformName": "android",
"appium:capture.networkConfig": {
"shaping": {
"down":5,
"up": 2
}
}
},

上面的json主体,我试图改变"属性来自"5"2";和";up"属性来自"2"1";使用下面的代码:

if(state == 'high')
{
let tempVal = caps[platform];  // let platform = 'android'
console.log("**********************");
console.log(tempVal);  // It's printing the json body.

for(let prep in tempVal)
{
tempVal[prep].shaping.down = 2;   //Not replaced.
tempVa[prep].shaping.up = 1;    //Not replaced.
console.log(tempVal[prep].shaping.down); // It's not printing down and returned as undefined.
}
console.log("**********************")
}
if(state == 'high')
{
let tempVal = caps[platform];  // let platform = 'android'
console.log("**********************");
console.log(tempVal);  // It's printing the json body.
let prep = 'appium:capture.networkConfig';

tempVal[prep].shaping.down = 2;   
tempVa[prep].shaping.up = 1;    
console.log(tempVal[prep].shaping.down);  

console.log("**********************")
}

最新更新