public static String getComboBoxJsonBySqlFormat(List<Object> list, String column) { String[] columns = column.split(","); List<Map> workMesions = new ArrayList<Map>(); if (dbtype.equalsIgnoreCase("db2")) { for (Object i : list) { Object[] wm = (Object[]) i; // if(columns.length == wm.length){ HashMap map = new HashMap(); for (int j = 0; j < columns.length; j++) { map.put(columns[j], wm[j]); } workMesions.add(map); } } else { for (Object i : list) { Object[] wm = (Object[]) i; // if(columns.length == wm.length){ HashMap map = new HashMap(); for (int j = 0; j < columns.length; j++) { map.put(columns[j], wm[j]); } workMesions.add(map); } } // if(isneedall!=""&&isneedall!=null){ // for(int j=0;j<columns.length;j++){ // HashMap map = new HashMap(); // map.put(columns[j],""); // workMesions.add(map); // } // } StringBuilder tempJsonString = new StringBuilder(""); JSONValue JSONArray; try { JSONArray = JSONMapper.toJSON(workMesions); JsonString = JSONArray.render(true); } catch (MapperException e) { // TODO Auto-generated catch block e.printStackTrace(); } tempJsonString.append(JsonString); JsonString = tempJsonString.toString(); return JsonString; }
@Override public Map<String, Object> handleController(HttpServletRequest request) throws Exception { Map<String, Object> model = new HashMap<String, Object>(); Long id = Long.parseLong(request.getPathInfo().substring(8)); TestRun testRun = testRunDAO.getRunById(id); if (testRun == null) { throw new UnexistentResource("Test run with id = " + id + " doesn't exist"); } Long projectId = testRun.getProjectId(); Long testId = testRun.getTestId(); Long suiteRunId = testRun.getSuiteRunId(); model.put("testRun", testRun); if (projectId != null && projectId > 0) { model.put("project", projectDAO.getProject(projectId)); } if (testId != null && testId > 0) { model.put("test", testDAO.getTest(testId)); } if (suiteRunId != null && suiteRunId > 0) { model.put("suiteRun", testRunDAO.getSuiteRun(suiteRunId)); } model.put("testRunParameters", testRunDAO.getTestRunParameters(testRun.getId())); if (testRun.getIssueId() != null && testRun.getIssueId() > 0) { model.put("issue", issueDAO.getIssue(testRun.getIssueId())); } XmlReportRender reportRender = new XmlReportRender(); ReportNode reportNode = reportRender.decode(testRun.getReport()); updateReport(reportNode, 0, new IdGenerator()); JSONValue jsonValue = JSONMapper.toJSON(reportNode); String jsonString = jsonValue.render(false); model.put("report", reportNode); model.put("json", jsonString); return model; }
public static String getGridJsonFormat(int sumnum, List<Object> list) { String ddd = ""; if (sumnum == 0) { JsonString = "{totalProperty:0,root:);"; return "{totalProperty:" + sumnum + ",root:[]}"; } else { // StringBuffer tempJsonString =null; StringBuilder tempJsonString = new StringBuilder("{totalProperty:" + sumnum + ",root:"); JSONValue JSONArray; try { JSONArray = JSONMapper.toJSON(list); JsonString = JSONArray.render(true); } catch (MapperException e) { // TODO Auto-generated catch block e.printStackTrace(); } tempJsonString.append(JsonString); tempJsonString.append("}"); JsonString = tempJsonString.toString(); } return JsonString; }
public static String getGridJsonBySqlFormat(int sumnum, List<Object> list, String column) { if (sumnum == 0) { // System.out.println("总条数为0 ,没有数据可以格式化..."); return "{totalProperty:" + sumnum + ",root:[]}"; } else { // StringBuffer tempJsonString =null; String[] columns = column.split(","); List<Map> workMesions = new ArrayList<Map>(); if (dbtype.equalsIgnoreCase("db2")) { for (Object i : list) { Object[] wm = (Object[]) i; // if(columns.length == wm.length){ HashMap map = new HashMap(); for (int j = 0; j < columns.length; j++) { if (wm[j + 1] == null) { wm[j + 1] = ""; } if (wm[j + 1].getClass().isEnum()) { wm[j] = wm[j + 1].toString().trim(); } // System.out.println(wm[j]); map.put(columns[j], wm[j + 1]); } workMesions.add(map); // } // else{ // System.out.println(columns.length); // System.out.println(wm.length); // for(int j=0;j<wm.length;j++){ // System.out.println(wm[j]); // } // System.out.println("字段数量不符合,请核对column参数"); // } } } else { for (Object i : list) { Object[] wm = (Object[]) i; // if(columns.length == wm.length){ HashMap map = new HashMap(); for (int j = 0; j < columns.length; j++) { if (wm[j] == null) { wm[j] = ""; } if (wm[j].getClass().isEnum()) { wm[j] = wm[j].toString().trim(); } // System.out.println(wm[j]); map.put(columns[j], wm[j]); } workMesions.add(map); // } // else{ // System.out.println(columns.length); // System.out.println(wm.length); // for(int j=0;j<wm.length;j++){ // System.out.println(wm[j]); // } // System.out.println("字段数量不符合,请核对column参数"); // } } } StringBuilder tempJsonString = new StringBuilder(" { "); tempJsonString.append("totalProperty:" + sumnum + ",root:"); JSONValue JSONArray; try { JSONArray = JSONMapper.toJSON(workMesions); JsonString = JSONArray.render(true); } catch (MapperException e) { // TODO Auto-generated catch block e.printStackTrace(); } tempJsonString.append(JsonString); tempJsonString.append("}"); JsonString = tempJsonString.toString(); } return JsonString; }