org.codehaus.jettison.json.JSONObject.quote()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(152)

本文整理了Java中org.codehaus.jettison.json.JSONObject.quote()方法的一些代码示例,展示了JSONObject.quote()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.quote()方法的具体详情如下:
包路径:org.codehaus.jettison.json.JSONObject
类名称:JSONObject
方法名:quote

JSONObject.quote介绍

[英]Produce a string in double quotes with backslash sequences in all the right places. A backslash will be inserted within
[中]以双引号生成字符串,并在所有正确位置使用反斜杠序列。将在中插入反斜杠

代码示例

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

public static String getMapAsJson(Map<String, Object> objectMap) {
  String nullString = "null";
  StringBuffer sb = new StringBuffer("{");
  boolean firstIteration = true;
  for (Entry<String, Object> entry : objectMap.entrySet()) {
    if (!firstIteration) {
      sb.append(',');
    }
    sb.append(JSONObject.quote(entry.getKey()));
    sb.append(':');
    Object value = entry.getValue();
    if (value == null) {
      sb.append(nullString);
    } else if (value instanceof Boolean) {
      sb.append(((Boolean) value).booleanValue());
    } else if (value instanceof String) {
      sb.append(JSONObject.quote(value.toString()));
    } else {
      sb.append(value.toString());
    }
    firstIteration = false;
  }
  sb.append("}");
  return sb.toString();
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

public String getHiddenFieldsJson() {
  StringBuilder sb = new StringBuilder();
  sb.append("{");
  sb.append("\"hiddenFields\":[");
  for (int j=0;j<hiddenFields.size();j++) {
    sb.append("{\"name\":\"");
    sb.append(hiddenFields.get(j).getName());
    sb.append("\",\"val\":");
    sb.append(JSONObject.quote(hiddenFields.get(j).getValue()));
    sb.append("}");
    if (j < hiddenFields.size()-1) {
      sb.append(",");
    }
  }
  sb.append("]}");
  return sb.toString();
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Produce a string in double quotes with backslash sequences in all the
 * right places. A backslash will be inserted within &lt;/, allowing JSON
 * text to be delivered in HTML. In JSON text, a string cannot contain a
 * control character or an unescaped quote or backslash.
 * @param string A String
 * @return  A String correctly formatted for insertion in a JSON text.
 */
public static String quote(String string) {
  return quote(string, true);
}
public static String quote(String string, boolean escapeForwardSlashAlways) {

代码示例来源:origin: org.codehaus.jettison/jettison

private double doGetDouble(String key, Object o) throws JSONException {
  try {
    return o instanceof Number ?
      ((Number)o).doubleValue() : 
      Double.valueOf((String)o).doubleValue();
  } catch (Exception e) {
    throw new JSONException("JSONObject[" + quote(key) +
      "] is not a number.");
  }
}

代码示例来源:origin: org.codehaus.jettison/jettison

private boolean doGetBoolean(String key, Object o) throws JSONException {
  if (o.equals(Boolean.FALSE) ||
      (o instanceof String &&
      ((String)o).equalsIgnoreCase("false"))) {
    return false;
  } else if (o.equals(Boolean.TRUE) ||
      (o instanceof String &&
      ((String)o).equalsIgnoreCase("true"))) {
    return true;
  }
  throw new JSONException("JSONObject[" + quote(key) +
      "] is not a Boolean.");
}

代码示例来源:origin: org.codehaus.jettison/jettison

sb.append(quote(o.toString(), escapeForwardSlashAlways));
sb.append(':');
sb.append(valueToString(this.myHashMap.get(o), escapeForwardSlashAlways));

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Get the value object associated with a key.
 *
 * @param key   A key string.
 * @return      The object associated with the key.
 * @throws   JSONException if the key is not found.
 */
public Object get(String key) throws JSONException {
  Object o = opt(key);
  if (o == null) {
    throw new JSONException("JSONObject[" + quote(key) +
        "] not found.");
  }
  return o;
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Get the JSONObject value associated with a key.
 *
 * @param key   A key string.
 * @return      A JSONObject which is the value.
 * @throws   JSONException if the key is not found or
 *  if the value is not a JSONObject.
 */
public JSONObject getJSONObject(String key) throws JSONException {
  Object o = get(key);
  if (o instanceof JSONObject) {
    return (JSONObject)o;
  }
  throw new JSONException("JSONObject[" + quote(key) +
      "] is not a JSONObject.");
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Get the JSONArray value associated with a key.
 *
 * @param key   A key string.
 * @return      A JSONArray which is the value.
 * @throws   JSONException if the key is not found or
 *  if the value is not a JSONArray.
 */
public JSONArray getJSONArray(String key) throws JSONException {
  Object o = get(key);
  if (o instanceof JSONArray) {
    return (JSONArray)o;
  }
  throw new JSONException("JSONObject[" + quote(key) +
      "] is not a JSONArray.");
}

代码示例来源:origin: org.codehaus.jettison/jettison

if (n == 1) {
  o = keys.next();
  sb.append(quote(o.toString(), escapeForwardSlashAlways));
  sb.append(": ");
  sb.append(valueToString(this.myHashMap.get(o), indentFactor,
      sb.append(' ');
    sb.append(quote(o.toString()));
    sb.append(": ");
    sb.append(valueToString(this.myHashMap.get(o), indentFactor,

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Append a key. The key will be associated with the next value. In an
 * object, every value must be preceded by a key.
 * @param s A key string.
 * @return this
 * @throws JSONException If the key is out of place. For example, keys
 *  do not belong in arrays or if the key is null.
 */
public JSONWriter key(String s) throws JSONException {
  if (s == null) {
    throw new JSONException("Null key.");
  }
  if (this.mode == 'k') {
    try {
      if (this.comma) {
        this.writer.write(',');
      }
      this.writer.write(JSONObject.quote(s));
      this.writer.write(':');
      this.comma = false;
      this.mode = 'o';
      return this;
    } catch (IOException e) {
      throw new JSONException(e);
    }
  }
  throw new JSONException("Misplaced key.");
}

代码示例来源:origin: org.codehaus.jettison/jettison

&& ignoredElements != null && ignoredElements.contains(k);
if (!mayBeDropSimpleElement) {
  writer.write(quote(k, escapeForwardSlashAlways));
  writer.write(':');

代码示例来源:origin: org.codehaus.jettison/jettison

return value.toString();
return quote(value.toString(), escapeForwardSlash);

代码示例来源:origin: org.codehaus.jettison/jettison

return ((JSONArray)value).toString(indentFactor, indent);
return quote(value.toString(), escapeForwardSlash);

代码示例来源:origin: com.netflix.astyanax/astyanax-cassandra

private String jsonifyString(String str) {
    if (str == null) {
      str = "null";
    }
    if (str.length() > maxStringLength) {
      return JSONObject.quote(str.substring(0, maxStringLength) + "...");
    }
    else {
      return JSONObject.quote(str);
    }
  }
}

代码示例来源:origin: com.atlassian.jira/jira-rest-java-client-core

@Override
public Promise<Void> addWatcher(final URI watchersUri, final String username) {
  return post(watchersUri, JSONObject.quote(username));
}

代码示例来源:origin: org.openengsb.wrapped/jira-rest-java-client-core

@Override
public Promise<Void> addWatcher(final URI watchersUri, final String username) {
  return post(watchersUri, JSONObject.quote(username));
}

代码示例来源:origin: com.atlassian.jira/jira-rest-java-client-p3

@Override
public Promise<Void> addWatcher(final URI watchersUri, @Nullable final String username) {
  Request request = client.newRequest(watchersUri);
  if (username != null)
  {
    request.setEntity(JSONObject.quote(username));
  }
  return call(request.post());
}

代码示例来源:origin: com.atlassian.jira/jira-rest-java-client

@Override
  public Void call() throws Exception {
    final WebResource.Builder builder = client.resource(watchersUri).type(MediaType.APPLICATION_JSON_TYPE);
    if (username != null) {
      builder.post(JSONObject.quote(username));
    } else {
      builder.post();
    }
    return null;
  }
});

代码示例来源:origin: com.atlassian.jira/jira-rest-java-client-p3

@Override
  public Void call() throws Exception {
    final WebResource.Builder builder = client.resource(watchersUri).type(MediaType.APPLICATION_JSON_TYPE);
    if (username != null) {
      builder.post(JSONObject.quote(username));
    } else {
      builder.post();
    }
    return null;
  }
});

相关文章