You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
566 B
24 lines
566 B
6 months ago
|
/**
|
||
|
* @desc 对象序列化
|
||
|
* @param {Object} obj
|
||
|
* @return {String}
|
||
|
*/
|
||
|
|
||
|
var stringfyQs = function stringfyQs(obj) {
|
||
|
if (!obj) return '';
|
||
|
var pairs = [];
|
||
|
|
||
|
for (var key in obj) {
|
||
|
var value = obj[key];
|
||
|
if (value instanceof Array) {
|
||
|
for (var i = 0; i < value.length; ++i) {
|
||
|
pairs.push(encodeURIComponent(key + '[' + i + ']') + '=' + encodeURIComponent(value[i]));
|
||
|
}
|
||
|
continue;
|
||
|
}
|
||
|
pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]));
|
||
|
}
|
||
|
return pairs.join('&');
|
||
|
};
|
||
|
|
||
|
module.exports = stringfyQs;
|