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

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

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

JSONArray.getJSONObject介绍

[英]Get the JSONObject associated with an index.
[中]获取与索引关联的JSONObject。

代码示例

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

/**
 * Get the optional JSONObject associated with an index.
 * Null is returned if the key is not found, or null if the index has
 * no value, or if the value is not a JSONObject.
 *
 * @param index The index must be between 0 and length() - 1.
 * @return      A JSONObject value.
 */
public JSONObject optJSONObject(int index) {
  try {
    return getJSONObject(index);
  } catch (Exception e) {
    return null;
  }
}

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

public Parameters(SlingHttpServletRequest request) throws IOException, JSONException {
  final JSONObject json = new JSONObject(request.getParameter("params"));
  final List<String> customProperties = new ArrayList<String>();
  final List<String> groups = new ArrayList<String>();
  groupFilter = json.getString(GROUP_FILTER);
  JSONArray groupsJSON = json.getJSONArray(GROUPS);
  for (int i = 0; i < groupsJSON.length(); i++) {
    groups.add(groupsJSON.getString(i));
  }
  this.groups = groups.toArray(new String[groups.size()]);
  JSONArray customPropertiesJSON = json.getJSONArray(CUSTOM_PROPERTIES);
  for (int i = 0; i < customPropertiesJSON.length(); i++) {
    JSONObject tmp = customPropertiesJSON.getJSONObject(i);
    String relativePropertyPath = tmp.optString(RELATIVE_PROPERTY_PATH);
    if (StringUtils.isNotBlank(relativePropertyPath)) {
      customProperties.add(relativePropertyPath);
    }
  }
  this.customProperties = customProperties.toArray(new String[customProperties.size()]);
}

代码示例来源:origin: io.wcm/io.wcm.caconfig.editor

private ConfigurationCollectionPersistData parseCollectionConfigData(JSONObject jsonData, ConfigurationMetadata configMetadata) throws JSONException {
 List<ConfigurationPersistData> items = new ArrayList<>();
 JSONArray itemsObject = jsonData.getJSONArray("items");
 for (int i = 0; i < itemsObject.length(); i++) {
  JSONObject item = itemsObject.getJSONObject(i);
  items.add(parseConfigData(item, configMetadata));
 }
 Map<String, Object> properties = null;
 JSONObject propertiesObject = jsonData.optJSONObject("properties");
 if (propertiesObject != null) {
  properties = new HashMap<>();
  Iterator<String> propertyNames = propertiesObject.keys();
  while (propertyNames.hasNext()) {
   String propertyName = propertyNames.next();
   properties.put(propertyName, propertiesObject.get(propertyName));
  }
 }
 return new ConfigurationCollectionPersistData(items)
   .properties(properties);
}

代码示例来源: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: otros-systems/otroslogviewer

for (int i = 0; i < length; i++) {
 try {
  final JSONObject o = a.getJSONObject(i);
  final String searchMde = o.getString(SEARCH_MODE);
  final String query = o.getString(QUERY);

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

JSONArray results = json.getJSONArray("results").getJSONObject(0).getJSONArray("results");
StringBuilder builder = new StringBuilder();
for (int i = 0; i < results.length(); i++) {
  JSONObject result = results.getJSONObject(i);
  if (result.getBoolean("final")) {
    JSONObject firstAlternative = result.getJSONArray("alternatives").getJSONObject(0);
    String line = firstAlternative.getString("transcript");
    if (StringUtils.isNotBlank(line)) {

代码示例来源:origin: Adobe-Consulting-Services/acs-aem-tools

final JSONObject item = jsonArray.getJSONObject(i);

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

final JSONObject tmp = jsonArray.getJSONObject(i);
final String pattern = tmp.optString("pattern");

代码示例来源:origin: org.streampipes/streampipes-pipeline-management

JSONObject object = data.getJSONObject(i);
options.add(new Option(object.getString(value)));

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

private void filter(JSONObject typeObject, String resourcePath, ResourceResolver resourceResolver) throws JSONException {
  final JSONArray models = typeObject.getJSONArray(KEY_MODELS);
  final JSONArray newModels = new JSONArray();
  for (int i = 0; i < models.length(); i++) {
    final JSONObject modelObject = models.getJSONObject(i);
    final String path = modelObject.getString(KEY_MODEL_PATH);
    final Resource modelResource = resourceResolver.getResource(path);
    if (modelResource != null) {
      // we're looking for the appliesTo property on the jcr:content node, the wid value
      // is the path to the jcr:content/model node.
      final ValueMap properties = modelResource.getParent().getValueMap();
      final String[] allowedPaths = properties.get(PN_ALLOWED_PATHS, String[].class);
      if (allowedPaths == null) {
        newModels.put(modelObject);
      } else {
        for (final String allowedPath : allowedPaths) {
          if (resourcePath.matches(allowedPath)) {
            newModels.put(modelObject);
            break;
          }
        }
      }
    }
  }
  
  typeObject.put(KEY_MODELS, newModels);
}

代码示例来源:origin: streampipes/streampipes-ce

JSONObject object = data.getJSONObject(i);
options.add(new Option(object.getString(value)));

代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons

@SuppressWarnings("squid:S3776")
private void filter(org.apache.sling.commons.json.JSONObject typeObject, String resourcePath, ResourceResolver resourceResolver) 
    throws org.apache.sling.commons.json.JSONException {
  final org.apache.sling.commons.json.JSONArray models = typeObject.getJSONArray(KEY_MODELS);
  final org.apache.sling.commons.json.JSONArray newModels = new org.apache.sling.commons.json.JSONArray();
  for (int i = 0; i < models.length(); i++) {
    final org.apache.sling.commons.json.JSONObject modelObject = models.getJSONObject(i);
    final String path = modelObject.getString(KEY_MODEL_PATH);
    final Resource modelResource = resourceResolver.getResource(path);
    if (modelResource != null) {
      // we're looking for the appliesTo property on the jcr:content node, the wid value
      // is the path to the jcr:content/model node.
      final ValueMap properties = modelResource.getParent().getValueMap();
      final String[] allowedPaths = properties.get(PN_ALLOWED_PATHS, String[].class);
      if (allowedPaths == null) {
        newModels.put(modelObject);
      } else {
        for (final String allowedPath : allowedPaths) {
          if (resourcePath.matches(allowedPath)) {
            newModels.put(modelObject);
            break;
          }
        }
      }
    }
  }
  
  typeObject.put(KEY_MODELS, newModels);
}

相关文章