截取url的参数并转为对象(加寻找大牛解释)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了截取url的参数并转为对象(加寻找大牛解释)相关的知识,希望对你有一定的参考价值。
参考技术A urlLink = 'http://127.0.0.1/a/b/loginmobile? isShowTop=false&userId=san.zhang&Name= 张三 &DepName=%3d%e6%80%bb%e9%83%a8%26DepCode%3d100137&employeenumber=9sgDeL21u8Yo%2f X%2fi67uGFw%3d%3d&Identity_Token=ObI1IJNm2fhzBevPMFghUuQMhLRoN3TFBhmd3kpP%2fWivul 3eBw9eKEFDpExUkm8NULLrNQ%2fw2kFed8I%2bUAp83v1nYou3%2bQpoRflRd6yVF0KiRfSx%2frgQT g%3d%3'var params = urlLink.split("?")[1].split("&");
console.log(params)
//结果:[' isShowTop=false', 'userId=san.zhang', 'Name= 张三 ', 'DepName=%3d%e6%80%bb%e9%83%a8%26DepCode%3d100137', 'employeenumber=9sgDeL21u8Yo%2f X%2fi67uGFw%3d%3d', 'Identity_Token=ObI1IJNm2fhzBevPMFghUuQMhLRoN3TFBhm…bUAp83v1nYou3%2bQpoRflRd6yVF0KiRfSx%2frgQT g%3d%3']
var urlInkSubstr =
params.map(item => urlInkSubstr[item.split("=")[0]] = item.split("=")[1])
console.log(JSON.stringify(urlInkSubstr))
//结果:" isShowTop":"false","userId":"san.zhang","Name":" 张三 ","DepName":"%3d%e6%80%bb%e9%83%a8%26DepCode%3d100137","employeenumber":"9sgDeL21u8Yo%2f X%2fi67uGFw%3d%3d","Identity_Token":"ObI1IJNm2fhzBevPMFghUuQMhLRoN3TFBhmd3kpP%2fWivul 3eBw9eKEFDpExUkm8NULLrNQ%2fw2kFed8I%2bUAp83v1nYou3%2bQpoRflRd6yVF0KiRfSx%2frgQT g%3d%3"
params.map(item => urlInkSubstr[item.split("=")[0]] = item.split("=")[1])
求大牛解释:这里的item是是params的值吗?是字符串吗?urlInkSubstr[]定义的是对象为什么以数组来用?
以上是关于截取url的参数并转为对象(加寻找大牛解释)的主要内容,如果未能解决你的问题,请参考以下文章