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

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

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

JSONObject.optString介绍

[英]Get an optional string associated with a key. It returns an empty string if there is no such key. If the value is not a string and is not null, then it is coverted to a string.
[中]获取与键关联的可选字符串。如果没有这样的键,它将返回一个空字符串。如果值不是字符串且不为null,则将其转换为字符串。

代码示例

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

/**
 * Get an optional string associated with a key.
 * It returns an empty string if there is no such key. If the value is not
 * a string and is not null, then it is coverted to a string.
 *
 * @param key A key string.
 * @return A string which is the value.
 */
public String optString(final String key)
{
  return optString(key, "");
}

代码示例来源:origin: com.atlassian.jira/jira-issue-link-remote-jira-plugin

private static String appendNameAndDescription(final JSONObject json) throws JSONException
{
  final String name = json.getString("name");
  final String description = json.optString("description");
  if (StringUtils.isBlank(description))
  {
    return name;
  }
  return name + " - " + description;
}

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

protected final Date parseDate(JSONObject json, String dateElement, int version) throws ParseException {
  Date date = null;
  if (version == 0) {
    // for payload format version 0 the date format is serialized as formatted string
    String dateStringOrNull = json.optString(dateElement);
    if (StringUtils.isNotBlank(dateStringOrNull)) {
      date = getDateFormat().parse(dateStringOrNull);
    }
  } else if (version > 0) {
    // for payload format version 1 and higher date format is serialized as long
    date = new Date(json.optLong(dateElement));
  }
  return date;
}

代码示例来源:origin: com.marvelution.jira.plugins/jira-jenkins-plugin

/**
 * Helper method to get the optional {@link String} element of the given {@link JSONObject} given by the key given
 *
 * @param json the {@link JSONObject} to get the {@link String} value from
 * @param key  the key to get he corresponding value of
 * @return the {@link String} value, maybe {@code null}
 */
private String optJsonString(JSONObject json, String key) {
  if (json.has(key) && !json.isNull(key)) {
    return json.optString(key);
  } else {
    return null;
  }
}

代码示例来源:origin: com.atlassian.plugin.deflection/deflection-cse

private String getEmbedURL(JSONObject result) throws JSONException
{
  final JSONObject richSnippet = result.optJSONObject("richSnippet");
  if (richSnippet != null)
  {
    final JSONObject metatags = richSnippet.optJSONObject("metatags");
    if (metatags != null)
    {
      final String pageId = metatags.optString("ajsPageId", null);
      if (StringUtils.isNumeric(pageId))
      {
        final String[] hostnames = StringUtils.substringsBetween(result.getString("unescapedUrl"), "//", "/");
        if (hostnames.length == 1)
        {
          return String.format("https://%s/plugins/servlet/remotepageview?pageId=%s", hostnames[0], pageId);
        }
      }
    }
  }
  return "";
}

代码示例来源:origin: com.atlassian.jira/jira-issue-link-remote-jira-plugin

builder.statusIconUrl(status.getString("iconUrl"));
builder.statusName(status.getString("name"));
builder.statusDescription(status.optString("description"));
builder.statusIconTitle(appendNameAndDescription(status));

相关文章