Java JSONObject后首字母变小写的问题

public static String formatJson(String orgJson) {
  JSONObject jo = new JSONObject();
  try {
   JSONObject jsonObject = new JSONObject(orgJson);
   Iterator iterator = jsonObject.keys();

   while (iterator.hasNext()) {
    String key = (String) iterator.next();
    char chars[] = key.toCharArray();
    if (key.length() > 1 && Character.isLowerCase(key.charAt(0))) {
     chars[0] = Character.toUpperCase(chars[0]);
    }

    Boolean bl = jsonObject.isNull(key);
    if (bl) {
     jo.put(new String(chars), null);
    } else {
     Object object = jsonObject.get(key);
     try {
      if (object instanceof Number) {
       // Log.i("MainActivity-----------------",
       // "result:1");
       jo.put(new String(chars),
         ((Number) object).intValue());
      } else {
       // Log.i("MainActivity-----------------",
       // "result:2");
       jo.put(new String(chars), jsonObject.getString(key));
      }
     } catch (Exception e) {
      jo.put(new String(chars), jsonObject.getString(key));
     }
    }
   }
  } catch (Exception e) {

   e.printStackTrace();
  }
  return jo.toString();
 }



你可能感兴趣的:(Java JSONObject后首字母变小写的问题)