Пример #1
0
  private void stringifySlow(StringBuilder sb) {
    if (this == NULL) {
      sb.append("null");
      return;
    }
    if (isBoolean()) {
      sb.append(asBoolean());
      return;
    }
    if (isNumber()) {
      sb.append(asNumber());
      return;
    }
    if (isString()) {
      sb.append(JsonUtils.escapeValue(asString()));
      return;
    }
    if (isIndexed()) {
      sb.append("[");
      for (int i = 0, j = size(); i < j; i++) {
        if (i > 0) {
          sb.append(",");
        }
        get(i).stringifySlow(sb);
      }
      sb.append("]");
      return;
    }

    sb.append("{");
    boolean needsComma = false;
    for (String key : getPropertyKeys()) {
      if (needsComma) {
        sb.append(",");
      } else {
        needsComma = true;
      }
      JsoSplittable value = get(key);
      if (!value.isFunction()) {
        if ("$H".equals(key)) {
          // Ignore hashcode
          continue;
        }
        sb.append(JsonUtils.escapeValue(key));
        sb.append(":");
        value.stringifySlow(sb);
      }
    }
    sb.append("}");
  }
Пример #2
0
 public String getPayload() {
   if (isString()) {
     return JsonUtils.escapeValue(asString());
   }
   if (stringifyFastSupported()) {
     return stringifyFast();
   }
   return stringifySlow();
 }
 public static String quote(String raw) {
   return JsonUtils.escapeValue(raw);
 }