Пример #1
0
  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;
  }
Пример #2
0
  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;
  }
Пример #3
0
  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;
  }