org.apache.sling.commons.json.JSONObject.optJSONArray()方法的使用及代码示例

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

本文整理了Java中org.apache.sling.commons.json.JSONObject.optJSONArray()方法的一些代码示例,展示了JSONObject.optJSONArray()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.optJSONArray()方法的具体详情如下:
包路径:org.apache.sling.commons.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: com.adobe.acs/acs-aem-commons-bundle

/**
 * Visit each JSON Object in the JSON Array.
 *
 * @param jsonObject The JSON Array
 */
protected final void traverseJSONObject(final JSONObject jsonObject) {
  if (jsonObject == null) {
    return;
  }
  final Iterator<String> keys = jsonObject.keys();
  while (keys.hasNext()) {
    final String key = keys.next();
    if (jsonObject.optJSONObject(key) != null) {
      this.accept(jsonObject.optJSONObject(key));
    } else if (jsonObject.optJSONArray(key) != null) {
      this.accept(jsonObject.optJSONArray(key));
    }
  }
}

代码示例来源:origin: otros-systems/otroslogviewer

@Override
 public Optional<List<Session>> deserialize(String data) {
  final ArrayList<Session> sessions = new ArrayList<>();
  try {
   final JSONArray array = new JSONArray(data);
   for (int i = 0; i < array.length(); i++) {
    final JSONObject jsonObject = array.getJSONObject(i);
    String name = jsonObject.getString("name");
    final ArrayList<FileToOpen> fileToOpens = new ArrayList<>();
    final JSONArray filesArray = jsonObject.optJSONArray("filesToOpen");
    if (filesArray != null){
     for (int j = 0; j < filesArray.length(); j++) {
      final JSONObject filesToOpen = filesArray.getJSONObject(j);
      String uri = filesToOpen.getString("uri");
      Level level = Level.parse(filesToOpen.getString("level"));
      OpenMode openMode = OpenMode.valueOf(filesToOpen.getString("openMode"));
      String logImporter = filesToOpen.optString("logImporter", null);
      fileToOpens.add(new FileToOpen(uri, openMode, level, Optional.ofNullable(logImporter)));
     }
    }
    sessions.add(new Session(name, fileToOpens));
   }
  } catch (JSONException e) {
   LOGGER.error("Can't deserialize sessions: ", e);
   Optional.empty();
  }
  LOGGER.info("Returning deserialized sessions: " + sessions.size());
  return Optional.of(sessions);
 }
}

代码示例来源:origin: com.adobe.acs/acs-aem-commons-bundle

JSONObject params = new JSONObject(request.getParameter("params"));
JSONArray jsonArray = params.optJSONArray(PARAM_WORKFLOW_STATUSES);
for (int i = 0; i < jsonArray.length(); i++) {
  statuses.add(jsonArray.getString(i));
jsonArray = params.optJSONArray(PARAM_WORKFLOW_MODELS);
for (int i = 0; i < jsonArray.length(); i++) {
  models.add(jsonArray.getString(i));
jsonArray = params.optJSONArray(PARAM_WORKFLOW_PAYLOADS);
for (int i = 0; i < jsonArray.length(); i++) {
  final JSONObject tmp = jsonArray.getJSONObject(i);

代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json

/**
 * Append a JSON Object
 *
 * @param o
 * @return
 * @throws JSONException
 */
public JSONWriter writeObject(JSONObject o) throws JSONException {
  Iterator<String> keys = o.keys();
  this.object();
  while (keys.hasNext()) {
    String key = keys.next();
    this.key(key);
    JSONObject objVal = o.optJSONObject(key);
    if (objVal != null) {
      this.writeObject(objVal);
      continue;
    }
    JSONArray arrVal = o.optJSONArray(key);
    if (arrVal != null) {
      this.writeArray(arrVal);
      continue;
    }
    Object obj = o.opt(key);
    this.value(obj);
  }
  this.endObject();
  return this;
}

代码示例来源:origin: io.wcm/io.wcm.handler.richtext

JSONArray valueArray = metadata.optJSONArray(metadataPropertyName);
if (valueArray != null) {

相关文章