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

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

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

JSONObject.has介绍

[英]Determine if the JSONObject contains a specific key.
[中]确定JSONObject是否包含特定的键。

代码示例

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

public static boolean resultMatches(JSONObject result, Iterable<String> patternToMatch) throws JSONException
  {
    if (result.has("richSnippet"))
    {
      final JSONObject richSnippet = result.getJSONObject("richSnippet");
      if (richSnippet.has("metatags"))
      {
        final JSONObject metatags = richSnippet.getJSONObject("metatags");
        if (metatags.has("answersTags"))
        {
          final String tags = metatags.getString("answersTags");
          for (String pattern : patternToMatch)
          {
            if (tags.matches(pattern + ".*"))
            {
              return true;
            }
          }
        }
      }
    }
    return false;
  }
}

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

public static boolean resultMatches(JSONObject result, Iterable<String> patternToMatch) throws JSONException
  {
    if (result.has("richSnippet"))
    {
      final JSONObject richSnippet = result.getJSONObject("richSnippet");
      if (richSnippet.has("metatags"))
      {
        final JSONObject metatags = richSnippet.getJSONObject("metatags");
        if (metatags.has("confluenceSpaceKey"))
        {
          final String spaceKey = metatags.getString("confluenceSpaceKey");
          for (String pattern : patternToMatch)
          {
            if (spaceKey.matches(pattern))
            {
              return true;
            }
          }
        }
      }
    }
    return false;
  }
}

代码示例来源: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.jira/jira-core

@Override
public Set<String> getDismissedFlagsForUser(ApplicationUser user)
{
  JSONObject userDismissalData = getDismissalsForUser(user);
  try
  {
    Set<String> currentDismissals = newHashSet();
    Iterator<String> dismissedKeys = userDismissalData.keys();
    JSONObject resetTimes = getDismissalResets();
    while (dismissedKeys.hasNext())
    {
      String dismissedFlag = dismissedKeys.next();
      long lastDismissal = userDismissalData.getLong(dismissedFlag);
      if (!resetTimes.has(dismissedFlag) || resetTimes.getLong(dismissedFlag) < lastDismissal)
      {
        currentDismissals.add(dismissedFlag);
      }
    }
    return currentDismissals;
  }
  catch (JSONException e)
  {
    log.debug("Exception occurred while trying to retrieve dismissed flags:", e);
    return emptySet();
  }
}

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

if (!json.has(SharePermissionUtils.TYPE_KEY))
if (json.has(SharePermissionUtils.PARAM1_KEY))
  if (json.has(SharePermissionUtils.PARAM2_KEY))
else if (json.has(SharePermissionUtils.PARAM2_KEY))

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

@Nonnull
public static RemoteProject from(ApplicationLink applicationLink, final JSONObject jsonObject) throws JSONException
{
  Builder builder = new Builder();
  builder.applicationLink(applicationLink);
  builder.id(jsonObject.getLong("id"));
  builder.key(jsonObject.getString("key"));
  builder.name(jsonObject.getString("name"));
  if (jsonObject.has("description"))
    builder.description(jsonObject.getString("description"));
  if (jsonObject.has("url"))
    builder.url(jsonObject.getString("url"));
  if (jsonObject.has("lead"))
    builder.leadUser(RemoteUser.from(jsonObject.getJSONObject("lead")));
  if (jsonObject.has("avatarUrls"))
    builder.avatar(RemoteAvatar.from(jsonObject.getJSONObject("avatarUrls")));
  return builder.build();
}

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

@Override
public List<Job> getJobs() {
  List<Job> jobs = Lists.newArrayList();
  try {
    RestResponse response = executeGetRequest("/api/json", CALL_TIMEOUT);
    if (response.getJson() != null && response.getJson().has("jobs")) {
      JSONArray json = response.getJson().getJSONArray("jobs");
      LOGGER.info("Found {} jobs", new Object[] { json.length() });
      for (int index = 0; index < json.length(); index++) {
        final JSONObject jsonJob = json.getJSONObject(index);
        jobs.add(new Job(site.getId(), jsonJob.getString("name")));
      }
    } else {
      handleNoJsonResponse(response);
    }
  } catch (CredentialsRequiredException e) {
    LOGGER.error("Authentication failure on {} [{}]: {}", new Object[] { applicationLink.getName(),
                                       applicationLink.getDisplayUrl(), e.getMessage() });
  } catch (JSONException e) {
    LOGGER.error("Failed to get the Job list from {}: {}", applicationLink.getName(), e.getMessage());
  }
  return jobs;
}

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

if (object.has("causes")) {
      JSONArray causes = object.optJSONArray("causes");
      for (int ii = 0; ii < causes.length(); ii++) {
        final JSONObject cause = causes.getJSONObject(ii);
        if (cause.has("shortDescription")) {
    } else if (object.has("urlName") && "testReport".equals(object.getString("urlName"))) {
    final JSONObject culprit = culprits.getJSONObject(index);
    String id = optJsonString(culprit, "id");
    if (id == null && culprit.has("absoluteUrl")) {
      String absoluteUrl = culprit.getString("absoluteUrl");
      id = absoluteUrl.substring(absoluteUrl.lastIndexOf("/"));
if (jsonBuild.has("changeSet")) {
  final JSONObject changeSet = jsonBuild.optJSONObject("changeSet");
  if (changeSet != null && changeSet.has("items")) {
    final JSONArray items = changeSet.optJSONArray("items");
    if (items != null && items.length() > 0) {
        String commitId = String.valueOf(index);
        for (String idField : COMMIT_ID_FIELDS) {
          if (item.has(idField) && !item.isNull(idField)) {
            commitId = item.getString(idField);
            break;

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

job.setInQueue(json.optBoolean("inQueue"));
final JSONObject firstBuild = json.optJSONObject("firstBuild");
if (firstBuild != null && firstBuild.has("number")) {
  job.setOldestBuild(firstBuild.optInt("number", -1));

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

builder.statusIconTitle(appendNameAndDescription(status));
if (status.has("statusCategory"))

相关文章