com.atlassian.jira.util.json.JSONObject.valueToString()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(214)

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

JSONObject.valueToString介绍

[英]Make a JSON text of an Object value. If the object has an value.toJSONString() method, then that method will be used to produce the JSON text. The method is required to produce a strictly conforming text. If the object does not contain a toJSONString method (which is the most common case), then a text will be produced by other means. If the value is an array or Collection, then a JSONArray will be made from it and its toJSONString method will be called. If the value is a MAP, then a JSONObject will be made from it and its toJSONString method will be called. Otherwise, the value's toString method will be called, and the result will be quoted.

Warning: This method assumes that the data structure is acyclical.
[中]生成对象值的JSON文本。如果对象有一个值。方法,则该方法将用于生成JSON文本。要求该方法生成严格一致的文本。如果对象不包含toJSONString方法(这是最常见的情况),那么将通过其他方式生成文本。如果该值是一个数组或集合,那么将从中生成一个JSONArray,并调用其toJSONString方法。如果该值是一个映射,那么将从中生成一个JSONObject,并调用其toJSONString方法。否则,将调用该值的toString方法,并引用结果。
警告:此方法假定数据结构是非循环的。

代码示例

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

/**
   * Util for transforming objects of any type (including arrays, standard primitive wrapper types, beans) into a
   * valid JSON string, which can be directly embedded in <script> section in HTML page. Because parsing of
   * <script> is immediately terminated by web browsers when </ sequence is found (usually </script>
   * marks the end of script section, but browsers are lazy) this method also escapes each "</" into "<\/"
   *
   * @param o object to convert to JSON string, for null you will get "null" string (without qutoes)
   * @return object converted to its JSON representation
   * @deprecated Since v6.4 use {@link com.atlassian.adapter.jackson.ObjectMapper#writeValueAsString(java.lang.Object)}
   * instead and properly escape output.
   */
  @Deprecated
  public static String toJsonString(@Nullable Object o)
  {
    try
    {
      return JSONObject.valueToString(o).replace("</", "<\\/");
    }
    catch (JSONException e)
    {
      throw new RuntimeException(e);
    }
  }
}

代码示例来源:origin: com.atlassian.jira/jira-api

/**
 * Make a string from the contents of this JSONArray. The
 * <code>separator</code> string is inserted between each element.
 * Warning: This method assumes that the data structure is acyclical.
 *
 * @param separator A string that will be inserted between the elements.
 * @return a string.
 * @throws JSONException If the array contains an invalid number.
 */
public String join(final String separator) throws JSONException
{
  final int len = length();
  final StringBuilder sb = new StringBuilder();
  for (int i = 0; i < len; i += 1)
  {
    if (i > 0)
    {
      sb.append(separator);
    }
    sb.append(JSONObject.valueToString(list.get(i)));
  }
  return sb.toString();
}

代码示例来源:origin: com.atlassian.jira/jira-api

if (len == 1)
  sb.append(JSONObject.valueToString(list.get(0), indentFactor, indent));
    sb.append(JSONObject.valueToString(list.get(i), indentFactor, newindent));

代码示例来源:origin: com.atlassian.jira/jira-api

sb.append(valueToString(map.get(o)));

代码示例来源:origin: com.atlassian.jira/jira-api

sb.append(quote(o.toString()));
sb.append(": ");
sb.append(valueToString(map.get(o), indentFactor, indent));
  sb.append(valueToString(map.get(o), indentFactor, newindent));

代码示例来源:origin: com.atlassian.jira/jira-api

writer.write(valueToString(v));

代码示例来源:origin: com.atlassian.jira/jira-api

writer.write(JSONObject.valueToString(v));

相关文章