沒有廢話,直接上代碼
var obj = {
name: "123",
sex: "4",
a: "1"
};
function objKeySort(obj) {
let newkey = Object.keys(obj).sort();
let newObj = {};
for (let i = 0; i < newkey.length; i++) {
newObj[newkey[i]] = obj[newkey[i]];
}
return newObj;
}
function getSigns(datas) {
let data = objKeySort(datas);
let url = "";
if (
typeof data == "undefined" ||
data == null ||
typeof data != "object"
) {
return "";
}
for (var k in data) {
url += (url.indexOf("=") != -1 ? "&" : "") + k + "=" + data[k];
}
return url;
}
console.log(getSigns(obj), 44);
}
複製代碼