转自:https://www.cnblogs.com/yeminglong/p/8910017.html
JavaScript代码如下:
function parseParam(param, key) { var paramStr = '' if (param instanceof String || param instanceof Number || param instanceof Boolean) { paramStr += '&' + key + '=' + encodeURIComponent(param) } else { $.each(param, function (i, p) { if (p == null || p == undefined) return true var k = key == null ? i : key + (param instanceof Array ? '[' + i + ']' : '.' + i) paramStr += '&' + parseParam(this, k) }) } return paramStr.substr(1) }
调用如下:
$.ajax({ type: "POST", dataType: "json", url: "/dictionarys/Test", traditional: false, data: parseParam(queryParams), success: function (response) { alert(JSON.stringify(response)); } });