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

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

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

JSONObject.optJSONArray介绍

[英]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.
[中]获取与键关联的可选JSONArray。如果没有这样的键,或者其值不是JSONArray,则返回null。

代码示例

代码示例来源:origin: apache/phoenix

public Set<String> getSubmittedYarnApps() throws Exception {
  String rmHost = PhoenixMRJobUtil.getActiveResourceManagerHost(conf, zkQuorum);
  Map<String, String> urlParams = new HashMap<String, String>();
  urlParams.put(YarnApplication.APP_STATES_ELEMENT, YarnApplication.state.NEW.toString()
      + "," + YarnApplication.state.ACCEPTED + "," + YarnApplication.state.SUBMITTED
      + "," + YarnApplication.state.RUNNING);
  int rmPort = PhoenixMRJobUtil.getRMPort(conf);
  String response = PhoenixMRJobUtil.getJobsInformationFromRM(rmHost, rmPort, urlParams);
  LOG.debug("Already Submitted/Running Apps = " + response);
  JSONObject jobsJson = new JSONObject(response);
  JSONObject appsJson = jobsJson.optJSONObject(YarnApplication.APPS_ELEMENT);
  Set<String> yarnApplicationSet = new HashSet<String>();
  if (appsJson == null) {
    return yarnApplicationSet;
  }
  JSONArray appJson = appsJson.optJSONArray(YarnApplication.APP_ELEMENT);
  if (appJson == null) {
    return yarnApplicationSet;
  }
  for (int i = 0; i < appJson.length(); i++) {
    Gson gson = new GsonBuilder().create();
    YarnApplication yarnApplication =
        gson.fromJson(appJson.getJSONObject(i).toString(),
          new TypeToken<YarnApplication>() {
          }.getType());
    yarnApplicationSet.add(yarnApplication.getName());
  }
  return yarnApplicationSet;
}

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

public static JSONArray getNestedOptionalArray(JSONObject json, final String... path) throws JSONException {
  for (int i = 0; json != null && i < path.length - 1; i++) {
    String s = path[i];
    json = json.optJSONObject(s);
  }
  return json == null ? null : json.optJSONArray(path[path.length - 1]);
}

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

@Override
  public Iterable<IssuelinksType> parse(JSONObject json) throws JSONException {
    return JsonParseUtil.parseJsonArray(json.optJSONArray("issueLinkTypes"), issueLinkTypeJsonParser);
  }
}

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

@Override
  public Iterable<IssuelinksType> parse(JSONObject json) throws JSONException {
    return JsonParseUtil.parseJsonArray(json.optJSONArray("issueLinkTypes"), issueLinkTypeJsonParser);
  }
}

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

public static JSONArray getNestedOptionalArray(JSONObject json, String... path) throws JSONException {
  for (int i = 0; json != null && i < path.length - 1; i++) {
    String s = path[i];
    json = json.optJSONObject(s);
  }
  return json == null ? null : json.optJSONArray(path[path.length - 1]);
}

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

@Override
  public Iterable<Group> parse(JSONObject json) throws JSONException {
    return JsonParseUtil.parseJsonArray(json.optJSONArray("groups"), new GroupJsonParser());
  }
}

代码示例来源:origin: cwensel/cascading

private Map<String, Map<String, Long>> parseDagCounters( JSONObject countersNode ) throws JSONException
 {
 if( countersNode == null )
  return null;
 JSONArray counterGroupNodes = countersNode.optJSONArray( ATSConstants.COUNTER_GROUPS );
 if( counterGroupNodes == null )
  return null;
 Map<String, Map<String, Long>> counters = new HashMap<>();
 int numCounterGroups = counterGroupNodes.length();
 for( int i = 0; i < numCounterGroups; i++ )
  parseCounterGroup( counters, counterGroupNodes.optJSONObject( i ) );
 return counters;
 }

代码示例来源:origin: cascading/cascading-hadoop2-tez-stats

private Map<String, Map<String, Long>> parseDagCounters( JSONObject countersNode ) throws JSONException
 {
 if( countersNode == null )
  return null;
 JSONArray counterGroupNodes = countersNode.optJSONArray( ATSConstants.COUNTER_GROUPS );
 if( counterGroupNodes == null )
  return null;
 Map<String, Map<String, Long>> counters = new HashMap<>();
 int numCounterGroups = counterGroupNodes.length();
 for( int i = 0; i < numCounterGroups; i++ )
  parseCounterGroup( counters, counterGroupNodes.optJSONObject( i ) );
 return counters;
 }

代码示例来源:origin: org.apache.tez/tez-history-parser

BaseInfo(JSONObject jsonObject) throws JSONException {
 final JSONObject otherInfoNode = jsonObject.getJSONObject(Constants.OTHER_INFO);
 //parse tez counters
 tezCounters = Utils.parseTezCountersFromJSON(
   otherInfoNode.optJSONObject(Constants.COUNTERS));
 //parse events
 eventList = Lists.newArrayList();
 Utils.parseEvents(jsonObject.optJSONArray(Constants.EVENTS), eventList);
}

代码示例来源:origin: com.tinkerpop.blueprints/blueprints-rexster-graph

protected void fillBuffer(final Queue<Edge> queue, final int start, final int end) {
    final JSONObject object = RestHelper.get(this.uri + this.createSeparator() + RexsterTokens.REXSTER_OFFSET_START + RexsterTokens.EQUALS + start + RexsterTokens.AND + RexsterTokens.REXSTER_OFFSET_END + RexsterTokens.EQUALS + end);

    JSONArray array = object.optJSONArray(RexsterTokens.RESULTS);
    for (int ix = 0; ix < array.length(); ix++) {
      queue.add(new RexsterEdge(array.optJSONObject(ix), this.graph));
    }
  }
}

代码示例来源:origin: org.apache.tez/tez-history-parser

public static List<DataDependencyEvent> parseDataEventDependencyFromJSON(JSONObject jsonObject) 
  throws JSONException {
 List<DataDependencyEvent> events = Lists.newArrayList();
 JSONArray fields = jsonObject.optJSONArray(Constants.LAST_DATA_EVENTS);
 for (int i=0; i<fields.length(); i++) {
  JSONObject eventMap = fields.getJSONObject(i);
  events.add(new DataDependencyEvent(
    StringInterner.weakIntern(eventMap.optString(EntityTypes.TEZ_TASK_ATTEMPT_ID.name())),
    eventMap.optLong(Constants.TIMESTAMP)));
 }
 return events;
}

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

@Override
public AuditRecordsData parse(final JSONObject json) throws JSONException {
  final Integer offset = json.getInt("offset");
  final Integer limit = json.getInt("limit");
  final Integer total = json.getInt("total");
  final OptionalIterable<AuditRecord> records = JsonParseUtil.parseOptionalJsonArray(json.optJSONArray("records"), singleAuditRecordJsonParser);
  return new AuditRecordsData(offset, limit, total, records);
}

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

@Override
  public CimProject parse(final JSONObject json) throws JSONException {
    final BasicProject basicProject = basicProjectJsonParser.parse(json);
    final JSONArray issueTypesArray = json.optJSONArray("issuetypes");
    final Iterable<CimIssueType> issueTypes = (issueTypesArray != null) ?
        issueTypesParser.parse(issueTypesArray) : Collections.<CimIssueType>emptyList();

    final Map<String, URI> avatarUris = JsonParseUtil.getAvatarUris(json.getJSONObject("avatarUrls"));
    return new CimProject(basicProject.getSelf(), basicProject.getKey(),
        basicProject.getName(), avatarUris, issueTypes);
  }
}

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

@Override
  public CimProject parse(final JSONObject json) throws JSONException {
    final BasicProject basicProject = basicProjectJsonParser.parse(json);
    final JSONArray issueTypesArray = json.optJSONArray("issuetypes");
    final Iterable<CimIssueType> issueTypes = (issueTypesArray != null) ?
        issueTypesParser.parse(issueTypesArray) : Collections.<CimIssueType>emptyList();

    final Map<String, URI> avatarUris = JsonParseUtil.getAvatarUris(json.getJSONObject("avatarUrls"));
    return new CimProject(basicProject.getSelf(), basicProject.getKey(),
        basicProject.getName(), avatarUris, issueTypes);
  }
}

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

@Override
  public CimProject parse(final JSONObject json) throws JSONException {
    final BasicProject basicProject = basicProjectJsonParser.parse(json);
    final JSONArray issueTypesArray = json.optJSONArray("issuetypes");
    final Iterable<CimIssueType> issueTypes = (issueTypesArray != null) ?
        issueTypesParser.parse(issueTypesArray) : Collections.<CimIssueType>emptyList();

    final Map<String, URI> avatarUris = JsonParseUtil.getAvatarUris(json.getJSONObject("avatarUrls"));
    return new CimProject(basicProject.getSelf(), basicProject.getKey(), basicProject.getId(),
        basicProject.getName(), avatarUris, issueTypes);
  }
}

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

@Override
  public CimProject parse(final JSONObject json) throws JSONException {
    final BasicProject basicProject = basicProjectJsonParser.parse(json);
    final JSONArray issueTypesArray = json.optJSONArray("issuetypes");
    final Iterable<CimIssueType> issueTypes = (issueTypesArray != null) ?
        issueTypesParser.parse(issueTypesArray) : Collections.<CimIssueType>emptyList();

    final Map<String, URI> avatarUris = JsonParseUtil.getAvatarUris(json.getJSONObject("avatarUrls"));
    return new CimProject(basicProject.getSelf(), basicProject.getKey(), basicProject.getId(),
        basicProject.getName(), avatarUris, issueTypes);
  }
}

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

private CimFieldInfo parseIssueFieldInfo(JSONObject json, String id) throws JSONException {
  final boolean required = json.getBoolean("required");
  final String name = JsonParseUtil.getOptionalString(json, "name");
  final FieldSchema schema = fieldSchemaJsonParser.parse(json.getJSONObject("schema"));
  final Set<StandardOperation> operations = parseOperations(json.getJSONArray("operations"));
  final Iterable<Object> allowedValues = parseAllowedValues(json.optJSONArray("allowedValues"), schema);
  final URI autoCompleteUri = JsonParseUtil.parseOptionalURI(json, "autoCompleteUrl");
  return new CimFieldInfo(id, required, name, schema, operations, allowedValues, autoCompleteUri);
}

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

private CimFieldInfo parseIssueFieldInfo(JSONObject json, String id) throws JSONException {
  final boolean required = json.getBoolean("required");
  final String name = JsonParseUtil.getOptionalString(json, "name");
  final FieldSchema schema = fieldSchemaJsonParser.parse(json.getJSONObject("schema"));
  final Set<StandardOperation> operations = parseOperations(json.getJSONArray("operations"));
  final Iterable<Object> allowedValues = parseAllowedValues(json.optJSONArray("allowedValues"), schema);
  final URI autoCompleteUri = JsonParseUtil.parseOptionalURI(json, "autoCompleteUrl");
  return new CimFieldInfo(id, required, name, schema, operations, allowedValues, autoCompleteUri);
}

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

private CimFieldInfo parseIssueFieldInfo(JSONObject json, String id) throws JSONException {
  final boolean required = json.getBoolean("required");
  final String name = JsonParseUtil.getOptionalString(json, "name");
  final FieldSchema schema = fieldSchemaJsonParser.parse(json.getJSONObject("schema"));
  final Set<StandardOperation> operations = parseOperations(json.getJSONArray("operations"));
  final Iterable<Object> allowedValues = parseAllowedValues(json.optJSONArray("allowedValues"), schema);
  final URI autoCompleteUri = JsonParseUtil.parseOptionalURI(json, "autoCompleteUrl");
  return new CimFieldInfo(id, required, name, schema, operations, allowedValues, autoCompleteUri);
}

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

private CimFieldInfo parseIssueFieldInfo(JSONObject json, String id) throws JSONException {
  final boolean required = json.getBoolean("required");
  final String name = JsonParseUtil.getOptionalString(json, "name");
  final FieldSchema schema = fieldSchemaJsonParser.parse(json.getJSONObject("schema"));
  final Set<StandardOperation> operations = parseOperations(json.getJSONArray("operations"));
  final Iterable<Object> allowedValues = parseAllowedValues(json.optJSONArray("allowedValues"), schema);
  final URI autoCompleteUri = JsonParseUtil.parseOptionalURI(json, "autoCompleteUrl");
  return new CimFieldInfo(id, required, name, schema, operations, allowedValues, autoCompleteUri);
}

相关文章