MyException - 我的异常网
当前位置:我的异常网» Java相关 » json ,Map转json,全部分了

json ,Map转json,全部分了(2)

www.MyException.Cn  网友分享于:2013-12-31  浏览:889次

  }

  static String intArray2Json(int[] array) {
  if (array.length==0)
  return "[]";
  StringBuilder sb = new StringBuilder(array.length << 4);
  sb.append('[');
  for (int o : array) {
  sb.append(Integer.toString(o));
  sb.append(',');
  }
  // set last ',' to ']':
  sb.setCharAt(sb.length()-1, ']');
  return sb.toString();
  }

  static String longArray2Json(long[] array) {
  if (array.length==0)
  return "[]";
  StringBuilder sb = new StringBuilder(array.length << 4);
  sb.append('[');
  for (long o : array) {
  sb.append(Long.toString(o));
  sb.append(',');
  }
  // set last ',' to ']':
  sb.setCharAt(sb.length()-1, ']');
  return sb.toString();
  }

  static String booleanArray2Json(boolean[] array) {
  if (array.length==0)
  return "[]";
  StringBuilder sb = new StringBuilder(array.length << 4);
  sb.append('[');
  for (boolean o : array) {
  sb.append(Boolean.toString(o));
  sb.append(',');
  }
  // set last ',' to ']':
  sb.setCharAt(sb.length()-1, ']');
  return sb.toString();
  }

  static String floatArray2Json(float[] array) {
  if (array.length==0)
  return "[]";
  StringBuilder sb = new StringBuilder(array.length << 4);
  sb.append('[');
  for (float o : array) {
  sb.append(Float.toString(o));
  sb.append(',');
  }
  // set last ',' to ']':
  sb.setCharAt(sb.length()-1, ']');
  return sb.toString();
  }

  static String doubleArray2Json(double[] array) {
  if (array.length==0)
  return "[]";
  StringBuilder sb = new StringBuilder(array.length << 4);
  sb.append('[');
  for (double o : array) {
  sb.append(Double.toString(o));
  sb.append(',');
  }
  // set last ',' to ']':
  sb.setCharAt(sb.length()-1, ']');
  return sb.toString();
  }

  static String shortArray2Json(short[] array) {
  if (array.length==0)
  return "[]";
  StringBuilder sb = new StringBuilder(array.length << 4);
  sb.append('[');
  for (short o : array) {
  sb.append(Short.toString(o));
  sb.append(',');
  }
  // set last ',' to ']':
  sb.setCharAt(sb.length()-1, ']');
  return sb.toString();
  }

  static String byteArray2Json(byte[] array) {
  if (array.length==0)
  return "[]";
  StringBuilder sb = new StringBuilder(array.length << 4);
  sb.append('[');
  for (byte o : array) {
  sb.append(Byte.toString(o));
  sb.append(',');
  }
  // set last ',' to ']':
  sb.setCharAt(sb.length()-1, ']');
  return sb.toString();
  }

  static String map2Json(Map<String, Object> map) {

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有