小程序中提交一下奇葩的json格式如:
const json={
'File[0].FilePath':'0000000',
'File[0].FileUploadName':'11111',
'File[0].FileType':'2222',
'File[1].FilePath':'3333',
'File[1].FileUploadName':'444',
'File[1].FileType':'5555',
}
他这当中的key值是真的蛋疼,至少对于我这种新手来说是。我做了如下方法进行处理;自己记录一下,以免以后再遇到:
const filearr = that.data.filepathlist
let Files = []
if(filearr.length!=0){
filearr.forEach(function (item, idnex, array) {
let files={
'FilePath':item.path,
'FileUploadName':(item.name).substring(0,49),
'FileType':item.type
}
Files.push(files)
})
}
let map = new Map();
let jsons = {}
Files.forEach((item, index) => {
let a = `Files[${index}].FilePath`
let b = `Files[${index}].FileUploadName`
let c = `Files[${index}].FileType`
map.set(a, item.FilePath)
map.set(b, item.FileUploadName)
map.set(c, item.FileType)
})
map.forEach((value, key) => {
jsons[key] = value
})
jsons['StartDate'] = startDate
jsons['EndDate'] = endDate
jsons['UseDate'] = usedate
jsons['HolidayType'] = holidaytype
jsons['Reason'] = reason
jsons['Memo'] = memo