var requestCol = []; for(var .... ){ var requestObj = new Object(); requestObj.id = 1; requestObj,name="Jim"; requestCol.push(requestObj); } $.post("request.action", {"requestCol":JSON.stringify(requestCol)}, function (result) { if(result.status=="error"){ //Error .... }else{ //Success .... } }, "json");
private Collection<RequestObj> requestCol; //注入 public void setRequestCol(String requestCol) { this.requestCol = (Collection<RequestObj>) JSONArray.toCollection(JSONArray.fromObject(requestCol), RequestObj.class); } public String saveRequestObj() throws IOException { HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType(HTML_CONTENT_TYPE); JSONObject jsonObj = new JSONObject(); try { //处理requestCol对象 } catch (SfjServiceException | SfjRuntimeTransactionException e) { //处理出现的异常 } finally { response.getWriter().print(jsonObj.toString()); } return NONE; }
使用JSON处理的jar包:json-lib-2.2.2-jdk15.jar