Exemple #1
0
 /**
  * Returns the hashcode of value.<br>
  * If null it will return JSONNull.getInstance().hashCode().<br>
  * If value is JSON, JSONFunction or String, value.hashCode is returned, otherwise the value is
  * transformed to a String an its hashcode is returned.
  */
 public static int hashCode(Object value) {
   if (value == null) {
     return JSONNull.getInstance().hashCode();
   } else if (value instanceof JSON || value instanceof String || value instanceof JSONFunction) {
     return value.hashCode();
   } else {
     return String.valueOf(value).hashCode();
   }
 }
Exemple #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();
  }
Exemple #3
0
 /** Tests if the obj is a javaScript null. */
 public static boolean isNull(Object obj) {
   if (obj instanceof JSONObject) {
     return ((JSONObject) obj).isNullObject();
   }
   return JSONNull.getInstance().equals(obj);
 }
Exemple #4
0
 private static String toString(JSONNull jsonNull) {
   return jsonNull.toString();
 }