Пример #1
0
 /** Creates a Map with all the properties of the JSONObject. */
 public static Map getProperties(JSONObject jsonObject) {
   Map properties = new HashMap();
   for (Iterator keys = jsonObject.keys(); keys.hasNext(); ) {
     String key = (String) keys.next();
     /*
      * String parsedKey = key; if( !JSONUtils.isJavaIdentifier( parsedKey ) ){
      * parsedKey = JSONUtils.convertToJavaIdentifier( key ); }
      */
     properties.put(key, getTypeClass(jsonObject.get(key)));
   }
   return properties;
 }
Пример #2
0
  private static String toString(JSONObject jsonObject) {
    if (jsonObject.isNullObject()) {
      return JSONNull.getInstance().toString();
    }
    Iterator keys = jsonObject.keys();
    StringBuffer sb = new StringBuffer("{");

    while (keys.hasNext()) {
      if (sb.length() > 1) {
        sb.append(',');
      }
      Object o = keys.next();
      sb.append(quote(o.toString()));
      sb.append(':');
      sb.append(toString(jsonObject.get(String.valueOf(o))));
    }
    sb.append('}');
    return sb.toString();
  }