首页 > 代码库 > 将url参数转换成json格式,然后批量给url地址拼接参数

将url参数转换成json格式,然后批量给url地址拼接参数

var string_a = urlArr[1];
var string = string_a.split(‘&‘);
var res = {};
for(var i = 0;i<string.length;i++){
var str = string[i].split(‘=‘);
res[str[0]]=str[1];
}

var arr = [];
for(var o in res){
arr.push(o);
var arrLen = arr.length;
}
var url_1 = "";
for(var i = 0 ; i<arrLen ; i++){
if(arr[i] == "user_id"){
res[arr[i]] = getCookie("user_id");
}
if(arr[i] == "user_token"){
res[arr[i]] = getCookie("user_token")
}
if(arr[i] == "app_version"){
arr.splice(arr[i],1);
arrLen = arrLen - 1;
}
if(arr[i] == "user_id"){
arr.splice(arr[i],1);
arrLen = arrLen - 1;
}
url_1 = url_1 + arr[i] + "=" + res[arr[i]] + "&";
}
url_1 = url_1.substring(0,url_1.length-1);
console.log(url_1);

  

将url参数转换成json格式,然后批量给url地址拼接参数