为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕姐4208626 2019-08-24 22:21:40
原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":""}]
查看完整描述

2 回答

?
ABOUTYOU

TA贡献1812条经验 获得超5个赞

修改原数组版
arr.forEach(item=>{
letts=item.exactTime.split(',')
ts.forEach((tm,index)=>{
item['Time'+(index+1)]=tm
})
})
                            
查看完整回答
反对 回复 2019-08-24
?
MMTTMM

TA贡献1869条经验 获得超4个赞

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<4;i++){
item['time'+(i+1)]=newTiem[i]||''
}
})
                            
查看完整回答
反对 回复 2019-08-24
  • 2 回答
  • 0 关注
  • 245 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信