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


Java JsonArray.getJsonObject方法代码示例

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


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

示例1: warningsFrom

import javax.json.JsonArray; //导入方法依赖的package包/类
private static Warnings warningsFrom(JsonObject deltaResult) {
    final Warnings ws = new Warnings();

    final JsonArray jsonWarnings = deltaResult.getJsonArray("warnings");

    for (int i = 0; i < jsonWarnings.size(); ++i) {
        final JsonObject w = jsonWarnings.getJsonObject(i);

        final WarningCategory category = new WarningCategory(w.getString("category"));
        final JsonArray jsonDetails = w.getJsonArray("details");

        List<String> ds = new ArrayList<>();
        for (int j=0; j < jsonDetails.size(); j++) {
            ds.add(jsonDetails.getString(j));
        }

        final List<String> details = new ArrayList<>(ds);

        ws.add(new Warning(category, details));
    }

    return ws;
}
 
开发者ID:empear-analytics,项目名称:codescene-jenkins-plugin,代码行数:24,代码来源:DeltaAnalysisResult.java

示例2: getCookies

import javax.json.JsonArray; //导入方法依赖的package包/类
public List<Cookie> getCookies() {
  List<Cookie> res = new ArrayList<>();
  JsonObject o = inspector.sendCommand(Page.getCookies());
  JsonArray cookies = o.getJsonArray("cookies");
  if (cookies != null) {
    for (int i = 0; i < cookies.size(); i++) {
      JsonObject cookie = cookies.getJsonObject(i);
      String name = cookie.getString("name");
      String value = cookie.getString("value");
      String domain = cookie.getString("domain");
      String path = cookie.getString("path");
      Date expiry = new Date(cookie.getJsonNumber("expires").longValue());
      boolean isSecure = cookie.getBoolean("secure");
      Cookie c = new Cookie(name, value, domain, path, expiry, isSecure);
      res.add(c);
    }
    return res;
  } else {
    // TODO
  }
  return null;
}
 
开发者ID:google,项目名称:devtools-driver,代码行数:23,代码来源:RemoteIOSWebDriver.java

示例3: about

import javax.json.JsonArray; //导入方法依赖的package包/类
@Override
public Authenticated about() throws IOException {
    final JsonArray online = this.server.storage().build()
        .getJsonArray("authenticated");
    for(int idx = 0; idx < online.size(); idx++) {
        final JsonObject user = online.getJsonObject(idx);
        if (user.getJsonObject(this.username) != null) {
            return new MkJsonAuthenticated(
                user.getJsonObject(this.username)
            );
        }
    }
    throw new IllegalStateException(
        "User " + this.username + " is not logged in!"
    );
}
 
开发者ID:decorators-squad,项目名称:versioneye-api,代码行数:17,代码来源:MkMe.java

示例4: getPublicKey

import javax.json.JsonArray; //导入方法依赖的package包/类
/**
 * Get the public key that is used to verify the JWT from the user service. We assume the key is
 * an RSA key.
 *
 * @throws NoSuchAlgorithmException
 */
private PublicKey getPublicKey()
    throws Base64Exception, InvalidKeySpecException, NoSuchAlgorithmException {
  String url =
      "https://" + libertyHostname + ":" + libertySslPort + "/jwt/ibm/api/jwtUserBuilder/jwk";
  Response response = processRequest(url, "GET", null, null);
  assertEquals(
      "HTTP response code should have been " + Status.OK.getStatusCode() + ".",
      Status.OK.getStatusCode(),
      response.getStatus());

  // Liberty returns the keys in an array.  We'll grab the first one (there
  // should only be one).
  JsonObject jwkResponse = toJsonObj(response.readEntity(String.class));
  JsonArray jwkArray = jwkResponse.getJsonArray("keys");
  JsonObject jwk = jwkArray.getJsonObject(0);
  BigInteger modulus = new BigInteger(1, Base64Utility.decode(jwk.getString("n"), true));
  BigInteger publicExponent = new BigInteger(1, Base64Utility.decode(jwk.getString("e"), true));
  return KeyFactory.getInstance("RSA")
      .generatePublic(new RSAPublicKeySpec(modulus, publicExponent));
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:27,代码来源:JWTVerifier.java

示例5: exceptionalStats

import javax.json.JsonArray; //导入方法依赖的package包/类
@Test
public void exceptionalStats() {
    try {
        invokeMethod("exceptional");
    } catch (Exception ex) {
    }
    //[{"hostName":"unknown","methodName":"public java.lang.String com.bmw.eve.fastandslow.boundary.Invoker.exceptional()",
    //"recentDuration":0,"minDuration":0,"maxDuration":0,"averageDuration":0,"numberOfExceptions":1,"numberOfInvocations":1,
    //"exception":"java.lang.IllegalStateException: Don't call me!","lastInvocationTimestamp":1469431094017,"totalDuration":0}]
    JsonArray invocationStatistics = this.methodsMonitoringTarget.
            request(MediaType.APPLICATION_JSON).
            get(JsonArray.class);
    assertThat(invocationStatistics.size(), is(1));
    System.out.println("invocationStatistics = " + invocationStatistics);
    long count = invocationStatistics.stream().map(a -> (JsonObject) a).
            map(i -> i.getString("methodName")).
            filter(m -> !m.contains("exceptional")).
            count();
    assertThat(count, is(0l));
    JsonObject invocation = invocationStatistics.getJsonObject(0);
    int numberOfInvocations = invocation.getInt("numberOfInvocations");
    assertThat(numberOfInvocations, is(1));
    int numberOfExceptions = invocation.getInt("numberOfExceptions");
    assertThat(numberOfExceptions, is(1));
}
 
开发者ID:AdamBien,项目名称:perceptor,代码行数:26,代码来源:MonitoringIT.java

示例6: getKey

import javax.json.JsonArray; //导入方法依赖的package包/类
private boolean getKey() throws IOException {
    String resp = makeQuery(POST, PROTOCOL + bridge.getIp() + API, IDENTBODY);
    if (resp != null) {
        JsonReader reader = Json.createReader(new StringReader(resp));
        JsonArray arr = reader.readArray();
        JsonObject obj = arr.getJsonObject(0);
        if (obj.containsKey("success")) {
            JsonObject success = obj.getJsonObject("success");
            bridge.setKey(success.getString("username"));
            LOG.info("Got key from bridge");
            return true;
        }

    }
    return false;
}
 
开发者ID:dainesch,项目名称:HueSense,代码行数:17,代码来源:HueComm.java

示例7: runTests

import javax.json.JsonArray; //导入方法依赖的package包/类
public TestResults runTests(String testPackageOrClassName) throws Exception {
    final RemoteTestHttpClient testClient = new RemoteTestHttpClient(serverBaseUrl + "/system/sling/junit",serverUsername,serverPassword,true);
    final TestResults r = new TestResults();
    final Map<String, String> options = new HashMap<String, String>();
    options.put("forceReload", "true");
    final RequestExecutor executor = testClient.runTests(testPackageOrClassName, null, "json", options);
    executor.assertContentType("application/json");
    String content = executor.getContent();
    if (!content.trim().isEmpty()) {
        final JsonArray json = JsonUtil.parseArray(content);

        for(int i = 0 ; i < json.size(); i++) {
            final JsonObject obj = json.getJsonObject(i);
            if("test".equals(obj.getString("INFO_TYPE"))) {
                r.testCount++;
                if(obj.containsKey("failure")) {
                    r.failures.add(JsonUtil.toString(obj.get("failure")));
                }
            }
        }
    }

    return r;
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:25,代码来源:ServerSideTestClient.java

示例8: parseAddress

import javax.json.JsonArray; //导入方法依赖的package包/类
@Override
public Address parseAddress(JsonObject json) {
    JsonArray result = json.getJsonArray("results");
    if (result != null) {
        JsonArray locations = result.getJsonObject(0).getJsonArray("locations");
        if (locations != null) {
            JsonObject location = locations.getJsonObject(0);

            Address address = new Address();

            if (location.containsKey("street")) {
                address.setStreet(location.getString("street"));
            }
            if (location.containsKey("adminArea5")) {
                address.setSettlement(location.getString("adminArea5"));
            }
            if (location.containsKey("adminArea4")) {
                address.setDistrict(location.getString("adminArea4"));
            }
            if (location.containsKey("adminArea3")) {
                address.setState(location.getString("adminArea3"));
            }
            if (location.containsKey("adminArea1")) {
                address.setCountry(location.getString("adminArea1").toUpperCase());
            }
            if (location.containsKey("postalCode")) {
                address.setPostcode(location.getString("postalCode"));
            }

            return address;
        }
    }
    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:35,代码来源:MapQuestGeocoder.java

示例9: getEntities

import javax.json.JsonArray; //导入方法依赖的package包/类
/**
 * Method handling HTTP GET requests. The returned object will be sent
 * to the client as "application/json" media type.
 *
 * @return Object that will be transformed to application/json response.
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getEntities(@QueryParam("id") String id, @QueryParam("type") String type,
                          @QueryParam("q") String q, @QueryParam("georel") String georel,
                          @QueryParam("geometry") String geometry, @QueryParam("coords") String coords,
                            @QueryParam("attrs") String attrs,
                          @QueryParam("options") List<String> options) {
    QueryData qd = new QueryData();
    if (id != null) {
        qd.entityIds = id;
    }

    if (type != null) {
        qd.types = type;
    }

    if (q != null) {
        qd.queryExpression = q;
    }

    if (georel != null) {
        qd.geoQuery = new GeoQueryData();
        qd.geoQuery.geoRel = georel;
        qd.geoQuery.coords = coords;
        qd.geoQuery.geometry = geometry;
    }

    if (attrs != null) {
        qd.attrs = attrs;
    }

    JsonbConfig config = new JsonbConfig();

    config.withAdapters(new EntityAdapter());
    Jsonb jsonb = JsonbBuilder.create(config);

    QueryResult result = retrieveNgsiEntity(qd, options);

    if (result.status != 200) {
        return Response.status(result.status).build();
    }
    else {
        if (options.indexOf("keyValues") != -1) {
            return Response.status(200).entity(result.result).build();
        }

        JsonArray array = result.result.asJsonArray();

        List<CEntity> resultEntities = new ArrayList<>();

        // Workaround to return a list
        StringBuffer stb = new StringBuffer("[");

        for(int j = 0; j < array.size(); j++) {
            JsonObject obj = array.getJsonObject(j);
            CEntity c3imEntity = Ngsi2NGSILD.toNGSILD(obj);
            resultEntities.add(c3imEntity);

            stb.append(jsonb.toJson(c3imEntity)).append(",");
        }

        if (stb.length() > 1) {
            stb.deleteCharAt(stb.length() - 1);
        }

        stb.append("]");

        return addJsonLinkHeader(Response.ok(stb.toString())).build();
    }
}
 
开发者ID:Fiware,项目名称:NGSI-LD_Wrapper,代码行数:77,代码来源:EntityResource.java

示例10: testImportAutoCheckoutNodes

import javax.json.JsonArray; //导入方法依赖的package包/类
/**
   * SLING-2108 Test import operation which auto checks out versionable nodes.
   */
  public void testImportAutoCheckoutNodes() throws IOException, JsonException {
      final String testPath = TEST_BASE_PATH;
      Map<String, String> props = new HashMap<String, String>();
      String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
      urlsToDelete.add(testNode);

      //1. first create some content to update.
      props.clear();
      props.put(SlingPostConstants.RP_OPERATION,
      		SlingPostConstants.OPERATION_IMPORT);

      String testNodeName = "testNode_" + String.valueOf(random.nextInt());
      props.put(SlingPostConstants.RP_NODE_NAME_HINT, testNodeName);
      testFile = getTestFile(getClass().getResourceAsStream("/integration-test/servlets/post/testimport3.json"));
      props.put(SlingPostConstants.RP_CONTENT_TYPE, "json");
      props.put(SlingPostConstants.RP_REDIRECT_TO, SERVLET_CONTEXT + testPath + "/*");
      props.put(SlingPostConstants.RP_CHECKIN, "true");
      String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath, new NameValuePairList(props), null, true,
      		testFile, SlingPostConstants.RP_CONTENT_FILE, null);

      // assert content at new location
      String content = getContent(importedNodeUrl + ".json", CONTENT_TYPE_JSON);

JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);

//assert that the versionable node is checked in.
assertFalse(jsonObj.getBoolean("jcr:isCheckedOut"));


//2. try an update with the :autoCheckout value set to false
      List<NameValuePair> postParams = new ArrayList<NameValuePair>();
      postParams.add(new NameValuePair(SlingPostConstants.RP_OPERATION,
      						SlingPostConstants.OPERATION_IMPORT));
      postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT_TYPE, "json"));
      postParams.add(new NameValuePair(SlingPostConstants.RP_CHECKIN, "true"));
      postParams.add(new NameValuePair(SlingPostConstants.RP_REPLACE_PROPERTIES, "true"));
      postParams.add(new NameValuePair(SlingPostConstants.RP_AUTO_CHECKOUT, "false"));
      postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT, "{ \"abc\": \"def2\" }"));
      assertPostStatus(importedNodeUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, "Expected error from VersionException");

//3. now try an update with the :autoCheckout value set to true
      postParams.clear();
      postParams.add(new NameValuePair(SlingPostConstants.RP_OPERATION,
		SlingPostConstants.OPERATION_IMPORT));
postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT_TYPE, "json"));
postParams.add(new NameValuePair(SlingPostConstants.RP_CHECKIN, "true"));
postParams.add(new NameValuePair(SlingPostConstants.RP_REPLACE_PROPERTIES, "true"));
postParams.add(new NameValuePair(SlingPostConstants.RP_AUTO_CHECKOUT, "true"));
postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT, "{ \"abc\": \"def2\" }"));
postParams.add(new NameValuePair(":http-equiv-accept", "application/json,*/*;q=0.9"));
      HttpMethod post = assertPostStatus(importedNodeUrl, HttpServletResponse.SC_CREATED, postParams, "Expected 201 status");
      
      String responseBodyAsString = post.getResponseBodyAsString();
JsonObject responseJSON = JsonUtil.parseObject(responseBodyAsString);
      JsonArray changes = responseJSON.getJsonArray("changes");
      JsonObject checkoutChange = changes.getJsonObject(0);
      assertEquals("checkout", checkoutChange.getString("type"));

      // assert content at new location
      String content2 = getContent(importedNodeUrl + ".json", CONTENT_TYPE_JSON);

JsonObject jsonObj2 = JsonUtil.parseObject(content2);
assertNotNull(jsonObj2);

//make sure it was really updated
assertEquals("def2", jsonObj2.getString("abc"));

//assert that the versionable node is checked back in.
assertFalse(jsonObj.getBoolean("jcr:isCheckedOut"));		
  }
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:75,代码来源:PostServletImportTest.java


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