有人可以幫助我使用javascript修改JSON對象,目前我使用角度js並從文件中獲取JSON數據。但我想修改下面的JSON並相應地進行處理。JavaScript中的JSON對象修改
當前JSON
{
"account": {
"premise": {
"zone": [
{
"id": 1,
"name": "Tps John?!? \"':7",
"type": "DOOR",
"functionType": "ENTRY_EXIT",
"sensor": [
{
"id": 1,
"type": "DRY_CONTACT",
"sourceType": "ZIGBEE",
"serialNumber": "000d6f00030cdbcf.1",
"model": "MCT-320 SMA",
"manufacturer": "Visonic",
"firmwareVersion": "0x00040008",
"hardwareVersion": "1"
}
]
},
{
"id": 2,
"name": "Motion Sensor $-*9$+%;47$9 %;:?2",
"type": "MOTION",
"functionType": "INTERIOR_FOLLOWER",
"sensor": [
{
"id": 2,
"type": "MOTION",
"sourceType": "ZIGBEE",
"serialNumber": "000d6f0004b2af93.1",
"model": "NEXT K85 SMA",
"manufacturer": "Visonic",
"firmwareVersion": "0x0004000b",
"hardwareVersion": "1"
}
]
}
]
}
}
}
但是從上面的JSON在開發區對象有傳感器的對象,但我想只保留傳感器如下
{
"account": {
"premise": {
"sensor": [
{
"id": 1,
"type": "DRY_CONTACT",
"sourceType": "ZIGBEE",
"serialNumber": "000d6f00030cdbcf.1",
"model": "MCT-320 SMA",
"manufacturer": "Visonic",
"firmwareVersion": "0x00040008",
"hardwareVersion": "1"
},
{
"id": 2,
"type": "MOTION",
"sourceType": "ZIGBEE",
"serialNumber": "000d6f0004b2af93.1",
"model": "NEXT K85 SMA",
"manufacturer": "Visonic",
"firmwareVersion": "0x0004000b",
"hardwareVersion": "1"
}
]
}
}
}
只是使用'JSON.parse()來'創建一個對象,刪除屬性你不這樣做的一個需要並使用'JSON.stringify()'序列化它' –