用struts2的json插件,直接action 生成 json数据 ,生成的数据是 {"jsona":[{"total":"a","total2":"a2"}]}
我前台显示用的是easyui,数据格式是[{"total":"a","total2":"a2"}],如何能直接action生成这种数据格式呢?
最好不通过jsp页面转
用struts2的json插件,直接action 生成 json数据 ,生成的数据是 {"jsona":[{"total":"a","total2":"a2"}]}
我前台显示用的是easyui,数据格式是[{"total":"a","total2":"a2"}],如何能直接action生成这种数据格式呢?
最好不通过jsp页面转
你用jquery回调的时候应该是把数组转换成json了吧.在后台转换吧。可以用这种方式。public ActionForward queryJsonString(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
logger.debug("json输出演示");
List list = tblorderdao.queryAllTblorder();
response.setContentType("text/plain;charset="
+ request.getCharacterEncoding());
PrintWriter pw = response.getWriter();
StringBuilder sb = new StringBuilder();
sb.append("{\"list\":[");
for (Tblorder tblorder : list) {
sb.append(String.format(
"{\"orderid\":%s,\"info\":\"%s\",\"customer\":\"%s\"},",
tblorder.getOrderid(), tblorder.getInfo(), tblorder
.getCustomer()));
}
if (!list.isEmpty()) {
sb.deleteCharAt(sb.length() - 1);
}
sb.append("]}");
pw.print(sb.toString());
return null;
}