我有一个json对象,如下所示。
var obj = {
"_id": "mand-configurations",
"server-host": "0.0.0.0",
"server-port": [1890, 1770, 2070],
"server-rest-api-timeout-in-millis": 3020,
"server-started": "server started successfuly",
"stopped-snmp": "server shutdown",
"connection-failed": "connection to pgw-server failed",
"request-time-out": "pgw-server request time out",
"notify-connection-failed-snmp": "connection to notification-server failed",
"subscription": {
"control-data": [
"app",
"sp"
],
"callback-url": "http://core.sdp:19980/notify",
"post-notification": true
},
"charging-start-time": "01:00",
"charging-schedulers": [
{
"scheduler-name": "fifteen",
"charging-scheduler-type": "fifteen-days",
"initial-delay": 10000,
"batch-execution": 10000,
"batch-execution-size": 100,
"charging-schedules": [
{
"charging-model-name": "fixed-fifteen"
}
]
}
]
}
在这里我得到一份副本并更改值。
var cpyObj = obj;
cpyObj["charging-schedulers"][0]["scheduler-name"] = "some value"
然后我需要用新的cpyObj值更新以前的obj。我怎么能做那件事。
答案 0 :(得分:0)
在“cpyObj”中进行任何更改也会更改“Obj”,因为不执行复制。所以是的,我相信你不需要做任何事情。