var urlstr = "www.baidu.com?a=1&b=xx&c"; var s = urlstr.split("?"); var argstr=""; console.log(s); if(s.length>1){ argstr = s[1]; } var parttern = /([a-z]+)(=)?([a-z0-9]*)/gi; var matches = parttern.exec(argstr); var arraymatches = []; while(matches){ arraymatches.push(matches); matches = parttern.exec(argstr); } console.log(arraymatches); var jsonop = {}; for(var i=0;i<arraymatches.length;i++){ var temp = arraymatches[i]; jsonop[temp[1]] = temp[3]; } console.log(jsonop); console.log( JSON.stringify(jsonop));
时间: 2024-10-23 09:25:15