发布网友 发布时间:2022-04-24 06:34
共2个回答
懂视网 时间:2022-04-24 10:55
加入对象为{name:'tom','class':{className:'class1'},classMates:[{name:'lily'}]}struts2期待的格式是 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); };
//调用: var obj={name:'tom','class':{className:'class1'},classMates:[{name:'lily'}]}; parseParam(obj); //结果: "name=tom&class.className=class1&classMates[0].name=lily" parseParam(obj,'stu'); //结果: "stu.name=tom&stu.class.className=class1&stu.classMates[0].name=lily"
以上这篇将json转换成struts参数的方法就是小编分享给大家的全部内容了
热心网友 时间:2022-04-24 08:03
jsp中通过$.ajax()传参数到action的写法如下: