function parseParam(t, e) {
var n = "";
if (
"string" == typeof t ||
"number" == typeof t ||
"boolean" == typeof t ||
null === t ||
void 0 === t
) {
n += "&" + e + "=" + t;
} else if (t instanceof Array) {
for (let i = 0; i < t.length; i++) {
var r =
null == e ? i : e + (t instanceof Array ? "[" + i + "]" : "." + i);
n += "&" + parseParam(t[i], r);
}
} else if (t instanceof Object) {
for (var i in t) {
var o =
null == e ? i : e + (t instanceof Array ? "[" + i + "]" : "." + i);
n += "&" + parseParam(t[i], o);
}
}
return n.substr(1);
},
参考https://www.bejson.com/jsontools/json2get/ 网站源码
源码代码:
function parseParam(t, e) {
var n = "";
if ("string" == typeof t || "number" == typeof t || "boolean" == typeof t || null === t || void 0 === t)
n += "&" + e + "=" + t;
else if (t instanceof Array)
$.each(t, function(i, o) {
var r = null == e ? i : e + (t instanceof Array ? "[" + i + "]" : "." + i);
n += "&" + parseParam(o, r)
});
else if (t instanceof Object)
for (var i in t) {
var o = null == e ? i : e + (t instanceof Array ? "[" + i + "]" : "." + i);
n += "&" + parseParam(t[i], o)
}
return n.substr(1)
}