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

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

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

JSONObject.opt介绍

[英]Get an optional value associated with a key.
[中]获取与键关联的可选值。

代码示例

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

/**
 * Get an optional JSONObject associated with a key.
 * It returns null if there is no such key, or if its value is not a
 * JSONObject.
 *
 * @param key A key string.
 * @return A JSONObject which is the value.
 */
public JSONObject optJSONObject(final String key)
{
  final Object o = opt(key);
  return o instanceof JSONObject ? (JSONObject) o : null;
}

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

/**
 * Get an optional JSONArray associated with a key.
 * It returns null if there is no such key, or if its value is not a
 * JSONArray.
 *
 * @param key A key string.
 * @return A JSONArray which is the value.
 */
public JSONArray optJSONArray(final String key)
{
  final Object o = opt(key);
  return o instanceof JSONArray ? (JSONArray) o : null;
}

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

/**
 * Get an optional string associated with a key.
 * It returns the defaultValue if there is no such key.
 *
 * @param key          A key string.
 * @param defaultValue The default.
 * @return A string which is the value.
 */
public String optString(final String key, final String defaultValue)
{
  final Object o = opt(key);
  return o != null ? o.toString() : defaultValue;
}

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

/**
 * Determine if the value associated with the key is null or if there is
 * no value.
 *
 * @param key A key string.
 * @return true if there is no value associated with the key or if
 *         the value is the JSONObject.NULL object.
 */
public boolean isNull(final String key)
{
  return JSONObject.NULL.isNull(opt(key));
}

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

/**
 * Get an optional double associated with a key, or the
 * defaultValue if there is no such key or if its value is not a number.
 * If the value is a string, an attempt will be made to evaluate it as
 * a number.
 *
 * @param key          A key string.
 * @param defaultValue The default.
 * @return An object which is the value.
 */
public double optDouble(final String key, final double defaultValue)
{
  try
  {
    final Object o = opt(key);
    return o instanceof Number ? ((Number) o).doubleValue() : Double.parseDouble((String) o);
  }
  catch (final Exception e)
  {
    return defaultValue;
  }
}

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

/**
 * Construct a JSONObject from a subset of another JSONObject.
 * An array of strings is used to identify the keys that should be copied.
 * Missing keys are ignored.
 *
 * @param jo    A JSONObject.
 * @param names An array of strings.
 * @throws JSONException If a value is a non-finite number.
 */
public JSONObject(final JSONObject jo, final String[] names) throws JSONException
{
  for (final String name : names)
  {
    putOpt(name, jo.opt(name));
  }
}

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

private Option<Object> getValueForPath(final Object jsonEntityProperty, final String path)
  {
    final String[] split = StringUtils.split(path, '.');
    Object value = jsonEntityProperty;
    for (final String currentKey : split)
    {
      if (value == null || !(value instanceof JSONObject))
      {
        return Option.none();
      }
      else
      {
        value = ((JSONObject) value).opt(currentKey);
      }
    }
    return Option.option(value);
  }
}

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

/**
 * 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(final String key) throws JSONException
{
  final Object o = opt(key);
  if (o == null)
  {
    throw new JSONException("JSONObject[" + quote(key) + "] not found.");
  }
  return o;
}

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

/**
 * Produce a JSONArray containing the values of the members of this
 * JSONObject.
 *
 * @param names A JSONArray containing a list of key strings. This
 *              determines the sequence of the values in the result.
 * @return A JSONArray of values.
 * @throws JSONException If any of the values are non-finite numbers.
 */
public JSONArray toJSONArray(final JSONArray names) throws JSONException
{
  if ((names == null) || (names.length() == 0))
  {
    return null;
  }
  final JSONArray ja = new JSONArray();
  for (int i = 0; i < names.length(); i += 1)
  {
    ja.put(opt(names.getString(i)));
  }
  return ja;
}

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

/**
 * Append values to the array under a key. If the key does not exist in the
 * JSONObject, then the key is put in the JSONObject with its value being a
 * JSONArray containing the value parameter. If the key was already
 * associated with a JSONArray, then the value parameter is appended to it.
 *
 * @param key   A key string.
 * @param value An object to be accumulated under the key.
 * @return this.
 * @throws JSONException If the key is null or if the current value
 *                       associated with the key is not a JSONArray.
 */
public JSONObject append(final String key, final Object value) throws JSONException
{
  testValidity(value);
  final Object o = opt(key);
  if (o == null)
  {
    put(key, new JSONArray().put(value));
  }
  else if (o instanceof JSONArray)
  {
    put(key, ((JSONArray) o).put(value));
  }
  else
  {
    throw new JSONException("JSONObject[" + key + "] is not a JSONArray.");
  }
  return this;
}

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

final Object o = opt(key);
if (o == null)

相关文章