Add object to {name: ' Tom ', ' class ': {className: ' Class1 '},classmates:[{name: ' Lily '}]}
Struts2 look forward to the format is name=tom&class.classname=class1&classmates[0].name=lily
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);
};
Call:
var obj={name: ' Tom ', ' class ': {className: ' Class1 '},classmates:[{name: ' Lily '}]};
ParseParam (obj);
Results:
"name=tom&class.classname=class1&classmates[0].name=lily"
parseparam (obj, ' Stu ');
Result:
"stu.name=tom&stu.class.classname=class1&stu.classmates[0].name=lily"
The above is to convert JSON to the parameters of struts is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.