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


Java JsonObject.getString方法代码示例

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


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

示例1: findElement

import javax.json.JsonObject; //导入方法依赖的package包/类
private RemoteWebElement findElement() throws Exception {
  JsonObject payload = getRequest().getPayload();
  String type = payload.getString("using");
  String value = payload.getString("value");

  RemoteWebElement element = null;

  if (getRequest().hasVariable(":reference")) {
    String reference = getRequest().getVariableValue(":reference");
    element = getWebDriver().createElement(reference);
  } else {
    element = getWebDriver().getDocument();
  }
  RemoteWebElement rwe;
  if ("link text".equals(type)) {
    rwe = element.findElementByLinkText(value, false);
  } else if ("partial link text".equals(type)) {
    rwe = element.findElementByLinkText(value, true);
  } else if ("xpath".equals(type)) {
    rwe = element.findElementByXpath(value);
  } else {
    String cssSelector = ToCSSSelectorConverter.convertToCSSSelector(type, value);
    rwe = element.findElementByCSSSelector(cssSelector);
  }
  return rwe;
}
 
开发者ID:google,项目名称:devtools-driver,代码行数:27,代码来源:FindElementHandler.java

示例2: read

import javax.json.JsonObject; //导入方法依赖的package包/类
public void read(JsonObject data) {
	this.data = data;
	
	type = data.getString("type", null);

	JsonArray jsonMacs = data.getJsonArray("macs");
	if (jsonMacs != null) {
		macs = new String[jsonMacs.size()];
		for (int i = 0; i < macs.length; ++i) {
			macs[i] = jsonMacs.getString(i);
		}
	}
	else {
		macs = new String[0];
	}
	
	throttled = data.getString("throttle", "true").equals("true");
	managed   = data.getString("managed", "false").equals("true");
}
 
开发者ID:privacyint,项目名称:thornsec-core,代码行数:20,代码来源:DeviceData.java

示例3: Group

import javax.json.JsonObject; //导入方法依赖的package包/类
/**
 * Create a group based on a JSON Object
 *
 * @param group The JSON Object with group information
 */
public Group(JsonObject group) {
  if (group.containsKey(JSON_KEY_GROUP_ID)) {
    id = group.getString(JSON_KEY_GROUP_ID);
  }
  name = group.getString(JSON_KEY_GROUP_NAME);

  JsonArray jsonMembers = group.getJsonArray(JSON_KEY_MEMBERS_LIST);
  if (jsonMembers != null) {
    members = new String[jsonMembers.size()];
    for (int i = 0; i < jsonMembers.size(); i++) {
      members[i] = jsonMembers.getString(i);
    }
  } else {
    members = new String[0];
  }
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:22,代码来源:Group.java

示例4: testUpdateUser

import javax.json.JsonObject; //导入方法依赖的package包/类
@Test 
public void testUpdateUser() throws IOException, JsonException {
	testUserId = H.createTestUser();
	
       String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".update.html";

	List<NameValuePair> postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair("displayName", "My Updated Test User"));
	postParams.add(new NameValuePair("url", "http://www.apache.org/updated"));
	// add nested param (SLING-6747)
	postParams.add(new NameValuePair("nested/param", "value"));
	Credentials creds = new UsernamePasswordCredentials(testUserId, "testPwd");
	H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
	
	//fetch the user profile json to verify the settings
	String getUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".json";
	H.assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null); //make sure the profile request returns some data
	String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
	assertNotNull(json);
	JsonObject jsonObj = JsonUtil.parseObject(json);
	assertEquals("My Updated Test User", jsonObj.getString("displayName"));
	assertEquals("http://www.apache.org/updated", jsonObj.getString("url"));
	// get path (SLING-6753)
	String path = jsonObj.getString("path");
	assertNotNull(path);
	// retrieve nested property via regular GET servlet
	getUrl = HttpTest.HTTP_BASE_URL + path + "/nested.json";
	json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
       assertNotNull(json);
       jsonObj = JsonUtil.parseObject(json);
       assertEquals("value", jsonObj.getString("param"));
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:33,代码来源:UpdateUserTest.java

示例5: adaptFromJson

import javax.json.JsonObject; //导入方法依赖的package包/类
@Override
public Booklet adaptFromJson(JsonObject json) {
    Booklet booklet = new Booklet(
            json.getString("title"),
            new Author(json.getString("firstName"), json.getString("lastName")));
    return booklet;
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:8,代码来源:BookletAdapter.java

示例6: processData

import javax.json.JsonObject; //导入方法依赖的package包/类
@Override
public void processData(List<String> jsaonData) {
    for (Iterator<String> iterator = jsaonData.iterator(); iterator.hasNext();) {
        String jsonStr = iterator.next();
        JsonReader jsonReader = Json.createReader(new StringReader(jsonStr));
        try {
            JsonObject jsonObject = jsonReader.readObject();
            String topicName = jsonObject.getString("topic", null);
            switch (topicName) {
            case "http":
                handleHttpTopic(jsonObject.getJsonObject("payload"));
                break;
            case "cpu":
                JsonNumber system = jsonObject.getJsonObject("payload").getJsonNumber("system");
                JsonNumber process = jsonObject.getJsonObject("payload").getJsonNumber("process");

                os_cpu_used_ratio.set(Double.valueOf(system.doubleValue()));
                process_cpu_used_ratio.set(Double.valueOf(process.doubleValue()));
                break;
            default:
                break;
            }
        } catch (JsonException je) {
            // Skip this object, log the exception and keep trying with
            // the rest of the list
            // System.err.println("Error in json: \n" + jsonStr);
            // je.printStackTrace();
        }
    }
}
 
开发者ID:RuntimeTools,项目名称:javametrics,代码行数:31,代码来源:Metrics.java

示例7: orderCoffee

import javax.json.JsonObject; //导入方法依赖的package包/类
@POST
public Response orderCoffee(JsonObject order) {
    final String beanOrigin = order.getString("beanOrigin", null);
    final CoffeeType coffeeType = CoffeeType.fromString(order.getString("coffeeType", null));

    if (beanOrigin == null || coffeeType == null)
        return Response.status(Response.Status.BAD_REQUEST).build();

    final UUID orderId = UUID.randomUUID();
    commandService.placeOrder(new OrderInfo(orderId, coffeeType, beanOrigin));

    final URI uri = uriInfo.getRequestUriBuilder().path(OrdersResource.class, "getOrder").build(orderId);
    return Response.accepted().header(HttpHeaders.LOCATION, uri).build();
}
 
开发者ID:sdaschner,项目名称:scalable-coffee-shop,代码行数:15,代码来源:OrdersResource.java

示例8: updateUser

import javax.json.JsonObject; //导入方法依赖的package包/类
/**
 * Update an existing user.
 *
 * @param id The ID of the user to update.
 * @param payload The fields of the user that should be updated.
 * @return Nothing.
 */
@PUT
@Path("/{id}")
@Consumes("application/json")
public Response updateUser(@PathParam("id") String id, JsonObject payload) {

  // Validate the JWT. The JWT should be in the 'users' group. We do not
  // check to see if the user is modifying their own profile.
  try {
    validateJWT(new HashSet<String>(Arrays.asList("users")));
  } catch (JWTException jwte) {
    return Response.status(Status.UNAUTHORIZED)
        .type(MediaType.TEXT_PLAIN)
        .entity(jwte.getMessage())
        .build();
  }

  // Retrieve the user from the database.
  DB database = mongo.getMongoDB();
  DBCollection dbCollection = database.getCollection(User.DB_COLLECTION_NAME);
  DBObject oldDbUser = dbCollection.findOne(new ObjectId(id));

  if (oldDbUser == null) {
    return Response.status(Status.BAD_REQUEST).entity("The user was not Found.").build();
  }

  // If the input object contains a new password, need to hash it for use in the database.
  User newUser = null;
  if (payload.containsKey("password")) {
    try {
      String rawPassword = payload.getString("password");
      String saltString = (String) (oldDbUser.get(User.JSON_KEY_USER_PASSWORD_SALT));
      PasswordUtility pwUtil = new PasswordUtility(rawPassword, saltString);
      JsonObject newJson =
          createJsonBuilder(payload)
              .add(User.JSON_KEY_USER_PASSWORD_HASH, pwUtil.getHashedPassword())
              .add(User.JSON_KEY_USER_PASSWORD_SALT, pwUtil.getSalt())
              .build();
      newUser = new User(newJson);
    } catch (Throwable t) {
      return Response.serverError().entity("Error updating password").build();
    }
  } else {
    newUser = new User(payload);
  }

  // Create the updated user object.  Only apply the fields that we want the
  // client to change (skip the internal fields).
  DBObject updateObject = new BasicDBObject("$set", newUser.getDBObjectForModify());
  dbCollection.findAndModify(oldDbUser, updateObject);

  return Response.ok().build();
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:60,代码来源:UserResource.java

示例9: testModifyAceForUser

import javax.json.JsonObject; //导入方法依赖的package包/类
@Test 
public void testModifyAceForUser() throws IOException, JsonException {
	testUserId = H.createTestUser();
	
	testFolderUrl = H.createTestFolder();
	
       String postUrl = testFolderUrl + ".modifyAce.html";

	List<NameValuePair> postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair("principalId", testUserId));
	postParams.add(new NameValuePair("[email protected]:read", "granted"));
	postParams.add(new NameValuePair("[email protected]:write", "denied"));
	postParams.add(new NameValuePair("[email protected]:modifyAccessControl", "bogus")); //invalid value should be ignored.
	
	Credentials creds = new UsernamePasswordCredentials("admin", "admin");
	H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
	
	
	//fetch the JSON for the acl to verify the settings.
	String getUrl = testFolderUrl + ".acl.json";

	String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
	assertNotNull(json);
	JsonObject jsonObject = JsonUtil.parseObject(json);
	assertEquals(1, jsonObject.size());
	
	JsonObject aceObject = jsonObject.getJsonObject(testUserId);
	assertNotNull(aceObject);
	
	String principalString = aceObject.getString("principal");
	assertEquals(testUserId, principalString);

        int order = aceObject.getInt("order");
        assertEquals(0, order);

	JsonArray grantedArray = aceObject.getJsonArray("granted");
	assertNotNull(grantedArray);
	assertEquals(1, grantedArray.size());
	assertEquals("jcr:read", grantedArray.getString(0));

	JsonArray deniedArray = aceObject.getJsonArray("denied");
	assertNotNull(deniedArray);
	assertEquals(1, deniedArray.size());
	assertEquals("jcr:write", deniedArray.getString(0));
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:46,代码来源:ModifyAceTest.java

示例10: getProp

import javax.json.JsonObject; //导入方法依赖的package包/类
private String getProp(String url) throws JsonException, IOException {
    final JsonObject content = JsonUtil.parseObject(getContent(url, CONTENT_TYPE_JSON));
    return content.getString("prop");
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:5,代码来源:VersionParameterTest.java

示例11: decode

import javax.json.JsonObject; //导入方法依赖的package包/类
@Override
protected Object decode(
        Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {

    HttpRequest request = (HttpRequest) msg;
    JsonObject root = Json.createReader(
            new StringReader(request.getContent().toString(StandardCharsets.US_ASCII))).readObject();

    if (!root.containsKey("_type") || !root.getString("_type").equals("location")) {
        sendResponse(channel, HttpResponseStatus.OK);
        return null;
    }

    Position position = new Position();
    position.setProtocol(getProtocolName());
    position.setValid(true);

    position.setLatitude(root.getJsonNumber("lat").doubleValue());
    position.setLongitude(root.getJsonNumber("lon").doubleValue());

    if (root.containsKey("vel")) {
        position.setSpeed(UnitsConverter.knotsFromKph(root.getInt("vel")));
    }
    if (root.containsKey("alt")) {
        position.setAltitude(root.getInt("alt"));
    }
    if (root.containsKey("cog")) {
        position.setCourse(root.getInt("cog"));
    }
    if (root.containsKey("acc")) {
        position.setAccuracy(root.getInt("acc"));
    }
    if (root.containsKey("t")) {
        position.set("t", root.getString("t"));
    }
    if (root.containsKey("batt")) {
        position.set(Position.KEY_BATTERY, root.getInt("batt"));
    }

    position.setTime(new Date(root.getJsonNumber("tst").longValue() * 1000));

    String uniqueId;

    if (root.containsKey("topic")) {
        uniqueId = root.getString("topic");
        if (root.containsKey("tid")) {
            position.set("tid", root.getString("tid"));
        }
    } else {
        uniqueId = root.getString("tid");
    }

    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, uniqueId);
    if (deviceSession == null) {
        sendResponse(channel, HttpResponseStatus.BAD_REQUEST);
        return null;
    }
    position.setDeviceId(deviceSession.getDeviceId());

    sendResponse(channel, HttpResponseStatus.OK);
    return position;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:63,代码来源:OwnTracksProtocolDecoder.java

示例12: BeansStored

import javax.json.JsonObject; //导入方法依赖的package包/类
public BeansStored(JsonObject jsonObject) {
    this(jsonObject.getString("beanOrigin"), jsonObject.getInt("amount"), Instant.parse(jsonObject.getString("instant")));
}
 
开发者ID:sdaschner,项目名称:scalable-coffee-shop,代码行数:4,代码来源:BeansStored.java

示例13: OrderCancelled

import javax.json.JsonObject; //导入方法依赖的package包/类
public OrderCancelled(JsonObject jsonObject) {
    this(UUID.fromString(jsonObject.getString("orderId")), jsonObject.getString("reason"), Instant.parse(jsonObject.getString("instant")));
}
 
开发者ID:sdaschner,项目名称:scalable-coffee-shop,代码行数:4,代码来源:OrderCancelled.java

示例14: testLoginWrongPassword

import javax.json.JsonObject; //导入方法依赖的package包/类
/** Tests login with the wrong password. */
@Test
public void testLoginWrongPassword() throws Exception {
  // Add a user.
  String loginAuthHeader =
      "Bearer "
          + new JWTVerifier()
              .createJWT("unauthenticated", new HashSet<String>(Arrays.asList("login")));
  User user =
      new User(null, "Niels", "Bohr", "nBohr", "@nBohr", "nBohrWishListLink", "myPassword");
  Response response = processRequest(userServiceURL, "POST", user.getJson(), loginAuthHeader);
  assertEquals(
      "HTTP response code should have been " + Status.OK.getStatusCode() + ".",
      Status.OK.getStatusCode(),
      response.getStatus());
  String authHeader = response.getHeaderString("Authorization");
  new JWTVerifier().validateJWT(authHeader);

  JsonObject responseJson = toJsonObj(response.readEntity(String.class));
  String dbId = responseJson.getString(User.JSON_KEY_USER_ID);
  user.setId(dbId);

  // Find user in the database.
  BasicDBObject dbUser =
      (BasicDBObject) database.getCollection("users").findOne(new ObjectId(dbId));
  assertTrue("User rFeynman was NOT found in database.", dbUser != null);
  assertTrue("User rFeynman does not contain expected data.", user.isEqual(dbUser));

  // Test 1: Login the user with an incorrect password.  This should fail.
  JsonObjectBuilder loginPayload = Json.createObjectBuilder();
  loginPayload.add(User.JSON_KEY_USER_NAME, user.userName);
  loginPayload.add(User.JSON_KEY_USER_PASSWORD, user.password + "X");

  response =
      processRequest(
          userServiceLoginURL, "POST", loginPayload.build().toString(), loginAuthHeader);
  assertEquals(
      "HTTP response code should have been " + Status.UNAUTHORIZED.getStatusCode() + ".",
      Status.UNAUTHORIZED.getStatusCode(),
      response.getStatus());
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:42,代码来源:LoginResourceTest.java

示例15: testEffectiveAclMergeForUser_SubsetOfPrivilegesDeniedOnChild2

import javax.json.JsonObject; //导入方法依赖的package包/类
/**
 * Test for SLING-2600, Effective ACL servlet returns incorrect information
 */
@Test 
public void testEffectiveAclMergeForUser_SubsetOfPrivilegesDeniedOnChild2() throws IOException, JsonException {
	testUserId = H.createTestUser();
	
	String testFolderUrl = H.createTestFolder("{ \"jcr:primaryType\": \"nt:unstructured\", \"propOne\" : \"propOneValue\", \"child\" : { \"childPropOne\" : true } }");
	
       String postUrl = testFolderUrl + ".modifyAce.html";

       //1. create an initial set of privileges
	List<NameValuePair> postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair("principalId", testUserId));
	postParams.add(new NameValuePair("[email protected]:all", "granted"));
	
	Credentials creds = new UsernamePasswordCredentials("admin", "admin");
	H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
	
	H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
	
	postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair("principalId", testUserId));
	postParams.add(new NameValuePair("[email protected]:removeNode", "denied"));
	
       postUrl = testFolderUrl + "/child.modifyAce.html";
	H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);

	
	//fetch the JSON for the eacl to verify the settings.
	String getUrl = testFolderUrl + "/child.eacl.json";

	String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
	assertNotNull(json);
	JsonObject jsonObject = JsonUtil.parseObject(json);
	
	JsonObject aceObject = jsonObject.getJsonObject(testUserId);
	assertNotNull(aceObject);

	String principalString = aceObject.getString("principal");
	assertEquals(testUserId, principalString);
	
	JsonArray grantedArray = aceObject.getJsonArray("granted");
	assertNotNull(grantedArray);
	assertTrue(grantedArray.size() >= 11);
	Set<String> grantedPrivilegeNames = new HashSet<String>();
	for (int i=0; i < grantedArray.size(); i++) {
		grantedPrivilegeNames.add(grantedArray.getString(i));
	}
	H.assertPrivilege(grantedPrivilegeNames,false,"jcr:all");
	H.assertPrivilege(grantedPrivilegeNames,false,"jcr:write");
	H.assertPrivilege(grantedPrivilegeNames,true,"jcr:read");
	H.assertPrivilege(grantedPrivilegeNames,true,"jcr:readAccessControl");
	H.assertPrivilege(grantedPrivilegeNames,true,"jcr:modifyAccessControl");
	H.assertPrivilege(grantedPrivilegeNames,true,"jcr:lockManagement");
	H.assertPrivilege(grantedPrivilegeNames,true,"jcr:versionManagement");
	H.assertPrivilege(grantedPrivilegeNames,true,"jcr:nodeTypeManagement");
	H.assertPrivilege(grantedPrivilegeNames,true,"jcr:retentionManagement");
	H.assertPrivilege(grantedPrivilegeNames,true,"jcr:lifecycleManagement");
	H.assertPrivilege(grantedPrivilegeNames,true,"jcr:modifyProperties");
	H.assertPrivilege(grantedPrivilegeNames,true,"jcr:addChildNodes");
	H.assertPrivilege(grantedPrivilegeNames,true,"jcr:removeChildNodes");

	JsonArray deniedArray = aceObject.getJsonArray("denied");
	assertNotNull(deniedArray);
	assertEquals(1, deniedArray.size());
	Set<String> deniedPrivilegeNames = new HashSet<String>();
	for (int i=0; i < deniedArray.size(); i++) {
		deniedPrivilegeNames.add(deniedArray.getString(i));
	}
	H.assertPrivilege(deniedPrivilegeNames, true, "jcr:removeNode");
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:73,代码来源:GetAclTest.java


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