var response = [{"2017-04-19T18:00:12+05:30":{"command":"00","device_id": "THB1", "voltage": "229", "e1": "00.00", "date_time":"18:00:12"}},{"2017-04-20T15:00:12+05:30":{"command":"00","device_id": "THB1", "voltage": "229", "e1": "00.00", "date_time":"15:00:12"}}]
一個JSON對象,我想將其轉換爲這樣的事情
[{"2017-04-19":{"command":"00","device_id": "THB1", "voltage": "229", "e1": "00.00", "date_time":"18:00:12"}},{"2017-04-20":{"command":"00","device_id": "THB1", "voltage": "229", "e1": "00.00", "date_time":"15:00:12"}}]
我已經試過這
for(var key in response){
if(response.hasOwnProperty(key)){
key = key.substring(0,10);
}
}
但這並不奏效。我哪裏錯了?
快速編輯: 目前的答案似乎工作,但有一些對象具有相同的日期,但不同的時間。因此,輸出僅顯示一個特定時間的數據。有什麼辦法可以解決這個問題嗎?例如:
var response = [{"2017-04-19T18:00:12+05:30":{"command":"00","device_id": "THB1", "voltage": "229", "e1": "00.00", "date_time":"18:00:12"}},{"2017-04-19T15:00:12+05:30":{"command":"00","device_id": "THB1", "voltage": "229", "e1": "00.00", "date_time":"15:00:12"}}]
我想這其輸出到像
[{"2017-04-19":[{"command":"00","device_id": "THB1", "voltage": "229", "e1": "00.00", "date_time":"18:00:12"},{"2017-04-19T15:00:12+05:30":{"command":"00","device_id": "THB1", "voltage": "229", "e1": "00.00", "date_time":"15:00:12"}]}]
你能請張貼的電流輸出,而不是«那並不沒有工作? –
我得到輸入作爲輸出 – Saikiran