function obj2params(obj) { var result = ''; var item; for (item in obj) { if(typeof obj[item] === 'object') { result += '&' + item + '=' + encodeURIComponent(JSON.stringify(obj[item])); }else { result += '&' + item + '=' + encodeURIComponent(obj[item]); } } if (result) { result = result.slice(1); } return result; }
转载于:https://my.oschina.net/u/3507508/blog/909876