当前位置: 首页>>代码示例>>Java>>正文


Java JSONArray.getJSONObject方法代码示例

本文整理汇总了Java中org.apache.sling.commons.json.JSONArray.getJSONObject方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.getJSONObject方法的具体用法?Java JSONArray.getJSONObject怎么用?Java JSONArray.getJSONObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.sling.commons.json.JSONArray的用法示例。


在下文中一共展示了JSONArray.getJSONObject方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testGetSuccessJSON

import org.apache.sling.commons.json.JSONArray; //导入方法依赖的package包/类
@Test
public void testGetSuccessJSON() throws Exception {

    final String actual = packageHelper.getSuccessJSON(packageOne);

    final JSONObject json = new JSONObject(actual);

    assertEquals("success", json.getString("status"));
    assertEquals("/etc/packages/testGroup/testPackageName-1.0.0.zip", json.getString("path"));

    final String[] expectedFilterSets = new String[]{
            "/a/b/c",
            "/d/e/f",
            "/g/h/i"
    };

    JSONArray actualArray = json.getJSONArray("filterSets");
    for(int i = 0; i < actualArray.length(); i++) {
        JSONObject tmp = actualArray.getJSONObject(i);
        assertTrue(ArrayUtils.contains(expectedFilterSets, tmp.get("rootPath")));
    }

    assertEquals(expectedFilterSets.length, actualArray.length());
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:25,代码来源:PackageHelperImplTest.java

示例2: deserialize

import org.apache.sling.commons.json.JSONArray; //导入方法依赖的package包/类
@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);
}
 
开发者ID:otros-systems,项目名称:otroslogviewer,代码行数:30,代码来源:SessionDeserializer.java

示例3: filter

import org.apache.sling.commons.json.JSONArray; //导入方法依赖的package包/类
@SuppressWarnings("squid:S3776")
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);
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:29,代码来源:WorkflowModelFilterPageInfoProvider.java

示例4: getResult

import org.apache.sling.commons.json.JSONArray; //导入方法依赖的package包/类
@Override
public Result getResult(String jobId) {
    log.debug("getting result for {}", jobId);
    Request request = httpClientFactory.get("/speech-to-text/api/v1/recognitions/" + jobId);
    try {
        JSONObject json = httpClientFactory.getExecutor().execute(request).handleResponse(HANDLER);

        log.trace("content: {}", json.toString(2));
        if (json.getString("status").equals("completed")) {
            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");
                    }
                }
            }

            String concatenated = builder.toString();
            concatenated = concatenated.replace("%HESITATION ", "");

            return new ResultImpl(true, concatenated);
        } else {
            return new ResultImpl(false, null);
        }
    } catch (Exception e) {
        log.error("Unable to get result. assuming failure.", e);
        return new ResultImpl(true, "error");
    }

}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:37,代码来源:TranscriptionServiceImpl.java

示例5: testGetPreviewJSON

import org.apache.sling.commons.json.JSONArray; //导入方法依赖的package包/类
@Test
public void testGetPreviewJSON() throws Exception {
    final Set<Resource> resources = new HashSet<Resource>();

    resources.add(slingContext.create().resource("/a/b/c"));
    resources.add(slingContext.create().resource("/d/e/f"));
    resources.add(slingContext.create().resource("/g/h/i"));


    final String actual = packageHelper.getPreviewJSON(resources);
    final JSONObject json = new JSONObject(actual);

    assertEquals("preview", json.getString("status"));
    assertEquals("Not applicable (Preview)", json.getString("path"));

    final String[] expectedFilterSets = new String[]{
            "/a/b/c",
            "/d/e/f",
            "/g/h/i"
    };

    JSONArray actualArray = json.getJSONArray("filterSets");
    for(int i = 0; i < actualArray.length(); i++) {
        JSONObject tmp = actualArray.getJSONObject(i);
        assertTrue(ArrayUtils.contains(expectedFilterSets, tmp.get("rootPath")));
    }

    assertEquals(expectedFilterSets.length, actualArray.length());
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:30,代码来源:PackageHelperImplTest.java

示例6: testGetPathFilterSetPreviewJSON

import org.apache.sling.commons.json.JSONArray; //导入方法依赖的package包/类
@Test
public void testGetPathFilterSetPreviewJSON() throws Exception {
    final List<PathFilterSet> pathFilterSets = new ArrayList<PathFilterSet>();
    pathFilterSets.add(new PathFilterSet("/a/b/c"));
    pathFilterSets.add(new PathFilterSet("/d/e/f"));
    pathFilterSets.add(new PathFilterSet("/g/h/i"));

    final String actual = packageHelper.getPathFilterSetPreviewJSON(pathFilterSets);
    final JSONObject json = new JSONObject(actual);

    assertEquals("preview", json.getString("status"));
    assertEquals("Not applicable (Preview)", json.getString("path"));

    final String[] expectedFilterSets = new String[]{
            "/a/b/c",
            "/d/e/f",
            "/g/h/i"
    };

    JSONArray actualArray = json.getJSONArray("filterSets");
    for(int i = 0; i < actualArray.length(); i++) {
        JSONObject tmp = actualArray.getJSONObject(i);
        assertTrue(ArrayUtils.contains(expectedFilterSets, tmp.get("rootPath")));
    }

    assertEquals(expectedFilterSets.length, actualArray.length());
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:28,代码来源:PackageHelperImplTest.java


注:本文中的org.apache.sling.commons.json.JSONArray.getJSONObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。