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

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

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

JSONObject.getJSONArray介绍

[英]Get the JSONArray value associated with a key.
[中]获取与键关联的JSONArray值。

代码示例

代码示例来源: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: com.adobe.acs/acs-aem-tools-bundle-livereload

private boolean isSupported(JSONObject obj) {
  try {
    if (obj.has(PROTOCOLS)) {
      JSONArray protocols = obj.getJSONArray(PROTOCOLS);
      for (int i = 0; i < protocols.length(); i++) {
        String protocol = protocols.getString(i);
        if (PROTOCOL_VERSION_7.equals(protocol)) {
          return true;
        }
      }
    }
  } catch (JSONException e) {
  }
  return false;
}

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

private boolean isSupported(JSONObject obj) {
  try {
    if (obj.has(PROTOCOLS)) {
      JSONArray protocols = obj.getJSONArray(PROTOCOLS);
      for (int i = 0; i < protocols.length(); i++) {
        String protocol = protocols.getString(i);
        if (PROTOCOL_VERSION_7.equals(protocol)) {
          return true;
        }
      }
    }
  } catch (JSONException e) {
  }
  return false;
}

代码示例来源: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)) {
      double firstTimestamp = firstAlternative.getJSONArray("timestamps").getJSONArray(0).getDouble(1);
      builder.append("[").append(firstTimestamp).append("s]: ").append(line).append("\n");

代码示例来源: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: io.wcm/io.wcm.caconfig.editor

private Object toArray(JSONObject properties, String propertyName, Class propertyType) throws JSONException {
 JSONArray array = properties.getJSONArray(propertyName);
 if (propertyType.equals(String.class)) {
  String[] values = new String[array.length()];

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

JSONArray jsonArray = json.getJSONArray("properties");

代码示例来源: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: 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);
}

相关文章