小白,请教各位大佬!如何对json进行处理得到另一形式的json大佬们有什么好的建议?

原json:[{"user":"A","time":"2019.07.23","exactTime":"08:37,12:00,13:34,17:02"},{"user":"A","time":"2019.07.24","exactTime":"08:40,12:00,13:33,17:03"},{"user":"A","time":"2019.07.25","exactTime":"08:25,13:28,17:11"},{"user":"A","time":"2019.07.26","exactTime":"08:20,17:14"},{"user":"B","time":"2019.07.23","exactTime":"08:37,12:04,13:37"},{"user":"B","time":"2019.07.24","exactTime":"12:03,13:28,17:04"},{"user":"B","time":"2019.07.25","exactTime":"08:50,11:50,14:00"}]
想得到这样的json格式(根据时间的格式,一般08:xx放到Time1,12:xx放到Time2,13:xx放到Time3,17:xx放到Time4):[{"user":"A","time":"2019.07.23","Time1":"08:37","Time2":"12:00","Time3":"13:34","Time4":"17:02"},{"user":"A","time":"2019.07.24","Time1":"08:40","Time2":"12:00","Time3":"13:33","Time4":"17:03"},{"user":"A","time":"2019.07.25","Time1":"08:25","Time2":"","Time3":"13:28","Time4":"17:11"},{"user":"A","time":"2019.07.26","Time1":"08:20","Time2":"","Time3":"","Time4":"17:14"},{"user":"B","time":"2019.07.23","Time1":"08:37","Time2":"12:00","Time3":"13:34","Time4":"17:02"},{"user":"B","time":"2019.07.24","Time1":"","Time2":"12:02","Time3":"13:28","Time4":"17:04"},{"user":"B","time":"2019.07.25","Time1":"08:50","Time2":"11:50","Time3":"14:00","Time4":""}]
慕姐4208626
浏览 246回答 2
2回答

ABOUTYOU

修改原数组版arr.forEach(item=>{letts=item.exactTime.split(',')ts.forEach((tm,index)=>{item['Time'+(index+1)]=tm})})

MMTTMM

lettimeArr=[{"user":"A","time":"2019.07.23","exactTime":"08:37,12:00,13:34,17:02"},{"user":"A","time":"2019.07.24","exactTime":"08:40,12:00,13:33,17:03"},{"user":"A","time":"2019.07.25","exactTime":"08:25,13:28,17:11"},{"user":"A","time":"2019.07.26","exactTime":"08:20,17:14"},{"user":"B","time":"2019.07.23","exactTime":"08:37,12:04,13:37"},{"user":"B","time":"2019.07.24","exactTime":"12:03,13:28,17:04"},{"user":"B","time":"2019.07.25","exactTime":"08:50,11:50,14:00"}]timeArr.forEach(item=>{letnewTiem=item.exactTime.split(',');for(leti=0;i
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript