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


Java JsonObject.get方法代码示例

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


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

示例1: isStatusOk

import javax.json.JsonObject; //导入方法依赖的package包/类
/**
    * Says if status is OK
    * @return true if status is OK
    */
   public boolean isStatusOk() {

if (jsonResult == null || jsonResult.isEmpty()) {
    return false;
}

try {
    JsonReader reader = Json.createReader(new StringReader(jsonResult));
    JsonStructure jsonst = reader.read();

    JsonObject object = (JsonObject) jsonst;
    JsonString status = (JsonString) object.get("status");

    if (status != null && status.getString().equals("OK")) {
	return true;
    } else {
	return false;
    }
} catch (Exception e) {
    this.parseException = e;
    invalidJsonStream = true;
    return false;
}

   }
 
开发者ID:kawansoft,项目名称:aceql-http,代码行数:30,代码来源:ResultAnalyzer.java

示例2: JwksResponse

import javax.json.JsonObject; //导入方法依赖的package包/类
JwksResponse(JsonObject jsonObject)
{
    JsonValue keys = jsonObject.get("keys");

    if (keys.getValueType() != JsonValue.ValueType.ARRAY)
    {
        _keys = Collections.emptyList();
    }
    else
    {
        _keys = Stream.of((JsonArray)keys)
                .filter(it -> it.getValueType() == JsonValue.ValueType.OBJECT)
                .map(it -> (JsonObject) it)
                .map(JsonWebKey::new)
                .collect(Collectors.toList());
    }
}
 
开发者ID:curityio,项目名称:oauth-filter-for-java,代码行数:18,代码来源:JwksResponse.java

示例3: Browser

import javax.json.JsonObject; //导入方法依赖的package包/类
/**
 * Constructs a new Browser from a Json object containing all the needed information
 * and 'translate' to appropriate name of platform.
 *
 * @param jsonObject Json object obtained from the configuration file.
 */
public Browser(JsonObject jsonObject) {
  String browserName = jsonObject.getString("browserName");
  String browserVersion = "?";
  String browserPlatform = "?";
  if (jsonObject.get("version") != null) {
    browserVersion = processVersion(jsonObject.getString("version"));
  }
  if (jsonObject.get("mobile") != null){
    JsonObject mobile = jsonObject.getJsonObject("mobile");
    browserPlatform = mobile.getString("platformName");
  } else {
    if (browserName.equalsIgnoreCase("MicrosoftEdge"))
      browserPlatform = "Windows 10";
    else
      browserPlatform = processPlatform(jsonObject.getString("platform"));
  }
  this.name = browserName;
  this.version = browserVersion;
  this.platform = browserPlatform;
}
 
开发者ID:webrtc,项目名称:KITE,代码行数:27,代码来源:Browser.java

示例4: toMap

import javax.json.JsonObject; //导入方法依赖的package包/类
public static Map<String, Object> toMap(JsonObject object) throws JsonException
{
   Map<String, Object> map = new HashMap<String, Object>();

   Iterator<String> keysItr = object.keySet().iterator();
   while(keysItr.hasNext()) {
      String key = keysItr.next();
      Object value = object.get(key);

      if(value instanceof JsonArray) {
         value = toList((JsonArray) value);
      }
      else if(value instanceof JsonObject) {
         value = toMap((JsonObject) value);
      }
      map.put(key, value);
   }
   return map;
}
 
开发者ID:forge,项目名称:springboot-addon,代码行数:20,代码来源:ConvertHelper.java

示例5: testMixinTypes

import javax.json.JsonObject; //导入方法依赖的package包/类
public void testMixinTypes() throws IOException, JsonException {
    
    // create a node without mixin node types
    final Map <String, String> props = new HashMap <String, String> ();
    props.put("jcr:primaryType","nt:unstructured");
    final String location = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, props);
    
    // assert no mixins
    String content = getContent(location + ".json", CONTENT_TYPE_JSON);
    JsonObject json = JsonUtil.parseObject(content);
    assertFalse("jcr:mixinTypes not expected to be set", json.containsKey("jcr:mixinTypes"));
    
    // add mixin
    props.clear();
    props.put("jcr:mixinTypes", "mix:versionable");
    testClient.createNode(location, props);
    
    content = getContent(location + ".json", CONTENT_TYPE_JSON);
    json = JsonUtil.parseObject(content);
    assertTrue("jcr:mixinTypes expected after setting them", json.containsKey("jcr:mixinTypes"));
    
    Object mixObject = json.get("jcr:mixinTypes");
    assertTrue("jcr:mixinTypes must be an array", mixObject instanceof JsonArray);
    
    JsonArray mix = (JsonArray) mixObject;
    assertTrue("jcr:mixinTypes must have a single entry", mix.size() == 1);
    assertEquals("jcr:mixinTypes must have correct value", "mix:versionable", mix.getString(0));

    // remove mixin
    props.clear();
    props.put("jcr:[email protected]", "-");
    testClient.createNode(location, props);

    content = getContent(location + ".json", CONTENT_TYPE_JSON);
    json = JsonUtil.parseObject(content);
    final boolean noMixins = !json.containsKey("jcr:mixinTypes") || json.getJsonArray("jcr:mixinTypes").size() == 0;
    assertTrue("no jcr:mixinTypes expected after clearing it", noMixins);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:39,代码来源:PostServletUpdateTest.java

示例6: verifyOrder

import javax.json.JsonObject; //导入方法依赖的package包/类
/**
 * Verify node order
 */
private void verifyOrder(String parentUrl, String[] names)
        throws IOException {
    // check that nodes appear in creation order in their parent's list of children
    final String content = getContent(parentUrl + ".1.json", CONTENT_TYPE_JSON);
    String expected = "";
    for (String n: names) {
        expected +=n + ",";
    }
    //assertJavascript(expected, content, TEST_SCRIPT);
    try {
        String actual = "";
        JsonObject obj = JsonUtil.parseObject(content);
        
        for (String name : obj.keySet()) {
            Object o = obj.get(name);
            if (o instanceof JsonObject) {
                actual += name + ",";
            }
        }
        assertEquals(expected, actual);
    } catch (JsonException e) {
        throw new IOException(e.toString());
    }
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:28,代码来源:PostServletOrderTest.java

示例7: JsonWebKey

import javax.json.JsonObject; //导入方法依赖的package包/类
JsonWebKey(JsonObject jsonObject)
{
    _jsonObject = jsonObject;

    JsonValue jsonValue = jsonObject.get("kty");

    _keyType = JsonWebKeyType.from(jsonValue);
}
 
开发者ID:curityio,项目名称:oauth-filter-for-java,代码行数:9,代码来源:JsonWebKey.java

示例8: getValue

import javax.json.JsonObject; //导入方法依赖的package包/类
/**
    * Returns the value for a name
    * @param name
    * @return the value
    */
   public String getValue(String name) {
if (name == null) {
    throw new NullPointerException("name is null!");
}

if (isInvalidJsonStream()) {
    return null;
}

try {
    JsonReader reader = Json.createReader(new StringReader(jsonResult));
    JsonStructure jsonst = reader.read();

    JsonObject object = (JsonObject) jsonst;
    JsonString value = (JsonString) object.get(name);
    
    if (value == null) {
        return null;
    }
    
    return value.getString();
} catch (Exception e) {
    this.parseException = e;
    return null;
}
   }
 
开发者ID:kawansoft,项目名称:aceql-http,代码行数:32,代码来源:ResultAnalyzer.java

示例9: getIntvalue

import javax.json.JsonObject; //导入方法依赖的package包/类
/**
    * Returns the int value for a name
    * @param name
    * @return the value
    */
   public int getIntvalue(String name) {
if (name == null) {
    throw new NullPointerException("name is null!");
}

if (isInvalidJsonStream()) {
    return -1;
}

try {
    JsonReader reader = Json.createReader(new StringReader(jsonResult));
    JsonStructure jsonst = reader.read();

    JsonObject object = (JsonObject) jsonst;
    JsonNumber value = (JsonNumber) object.get(name);
    
    if (value == null) {
        return -1;
    }
    
    return value.intValue();
} catch (Exception e) {
    this.parseException = e;
    return -1;
}
   }
 
开发者ID:kawansoft,项目名称:aceql-http,代码行数:32,代码来源:ResultAnalyzer.java

示例10: getErrorType

import javax.json.JsonObject; //导入方法依赖的package包/类
/**
    * Returns the error_type in case of failure
    * @return the error_type in case of failure, -1 if no error
    */
   public int getErrorType() {

if (isInvalidJsonStream()) {
    return 0;
}

try {
    JsonReader reader = Json.createReader(new StringReader(jsonResult));
    JsonStructure jsonst = reader.read();

    JsonObject object = (JsonObject) jsonst;
    JsonString status = (JsonString) object.get("status");

    if (status == null) {
        return -1;
    }
    
    JsonNumber errorType = (JsonNumber) object.get("error_type");
    
    if (errorType == null) {
        return -1;
    }
    else {
        return errorType.intValue();
    }
} catch (Exception e) {
    this.parseException = e;
    return -1;
}


   }
 
开发者ID:kawansoft,项目名称:aceql-http,代码行数:37,代码来源:ResultAnalyzer.java

示例11: getStackTrace

import javax.json.JsonObject; //导入方法依赖的package包/类
/**
    * Returns the stack_trace in case of failure
    * @return the stack_trace in case of failure, null if no stack_trace
    */
   public String getStackTrace() {

if (isInvalidJsonStream()) {
    return null;
}

try {
    JsonReader reader = Json.createReader(new StringReader(jsonResult));
    JsonStructure jsonst = reader.read();

    JsonObject object = (JsonObject) jsonst;
    JsonString status = (JsonString) object.get("status");

    if (status == null) {
        return null;
    }
    
    JsonString stackTrace = (JsonString) object.get("stack_trace");
    if (stackTrace == null) {
        return null;
    }
    else {
        return stackTrace.getString();
    }
} catch (Exception e) {
    this.parseException = e;
    return null;
}

   }
 
开发者ID:kawansoft,项目名称:aceql-http,代码行数:35,代码来源:ResultAnalyzer.java

示例12: assertExpectedJSON

import javax.json.JsonObject; //导入方法依赖的package包/类
protected void assertExpectedJSON(JsonObject expectedJson, JsonObject actualJson) throws JsonException {
 	Iterator<String> keys = expectedJson.keySet().iterator();
 	while (keys.hasNext()) {
 		String key = keys.next();

 		Object object = expectedJson.get(key);
 		Object object2 = actualJson.get(key);
if (object instanceof JsonObject) {
	assertTrue(object2 instanceof JsonObject);
 			assertExpectedJSON((JsonObject)object, (JsonObject)object2);
} else if (object instanceof JsonArray) {
	//compare the array
	assertTrue(object2 instanceof JsonArray);
	JsonArray actualArray = (JsonArray)object2;
	Set<Object> actualValuesSet = new HashSet<Object>();
	for (int i=0; i < actualArray.size(); i++) {
		actualValuesSet.add(actualArray.get(i));
	}

	JsonArray expectedArray = (JsonArray)object;
	for (int i=0; i < expectedArray.size(); i++) {
		assertTrue(actualValuesSet.contains(expectedArray.get(i)));
	}
 		} else {
 			assertEquals("Value of key: " + key, object, object2);
 		}
 	}
 }
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:29,代码来源:PostServletImportTest.java

示例13: testMergeAceForUserGrantAggregatePrivilegePartsAfterDenyAggregatePrivilege

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

       //1. setup an initial set of denied privileges for the test user
       List<NameValuePair> postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair("principalId", testUserId));
	postParams.add(new NameValuePair("[email protected]:versionManagement", "denied"));
	postParams.add(new NameValuePair("[email protected]:read", "denied"));
	postParams.add(new NameValuePair("[email protected]:modifyAccessControl", "denied")); 
	postParams.add(new NameValuePair("[email protected]:write", "denied")); 
	
	Credentials creds = new UsernamePasswordCredentials("admin", "admin");
	/*String json = */H.getAuthenticatedPostContent(creds, postUrl, HttpTest.CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);

       //2. now grant the all the privileges contained in the rep:write privilege
	postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair("principalId", testUserId));
	postParams.add(new NameValuePair("[email protected]:versionManagement", "granted"));
	postParams.add(new NameValuePair("[email protected]:read", "granted"));
	postParams.add(new NameValuePair("[email protected]:modifyAccessControl", "granted")); 
	postParams.add(new NameValuePair("[email protected]:nodeTypeManagement", "granted")); //sub-privilege of rep:write  
	postParams.add(new NameValuePair("[email protected]:write", "granted")); //sub-aggregate of rep:write  
	
	/*String json = */H.getAuthenticatedPostContent(creds, postUrl, HttpTest.CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);
	
	//3. verify that the acl has the correct values
	//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);
	
	assertEquals(testUserId, aceObject.getString("principal"));
	
	JsonArray grantedArray = aceObject.getJsonArray("granted");
	assertNotNull(grantedArray);
	Set<String> grantedPrivilegeNames = new HashSet<String>();
	for (int i=0; i < grantedArray.size(); i++) {
		grantedPrivilegeNames.add(grantedArray.getString(i));
	}
	H.assertPrivilege(grantedPrivilegeNames, true, "jcr:versionManagement");
	H.assertPrivilege(grantedPrivilegeNames, true, "jcr:read");
	H.assertPrivilege(grantedPrivilegeNames, true, "jcr:modifyAccessControl");
	H.assertPrivilege(grantedPrivilegeNames, true, "rep:write"); //jcr:nodeTypeManagement + jcr:write
       assertEquals("Expecting the correct number of privileges in " + grantedPrivilegeNames, 4, grantedPrivilegeNames.size());

	//should be nothing left in the denied set.
	Object deniedArray = aceObject.get("denied");
	assertNull(deniedArray);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:65,代码来源:ModifyAceTest.java

示例14: testEffectiveAclForUser

import javax.json.JsonObject; //导入方法依赖的package包/类
/**
 * Test for SLING-2600, Effective ACL servlet returns incorrect information
 */
@Test 
public void testEffectiveAclForUser() throws IOException, JsonException {
	testUserId = H.createTestUser();
	testUserId2 = 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]:write", "granted"));
	
	Credentials creds = new UsernamePasswordCredentials("admin", "admin");
	H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
	
	postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair("principalId", testUserId2));
	postParams.add(new NameValuePair("[email protected]:write", "granted"));
	
	H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
	
	postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair("principalId", testUserId2));
	postParams.add(new NameValuePair("[email protected]:lockManagement", "granted"));
	
       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);
	assertEquals(1, grantedArray.size());
	Set<String> grantedPrivilegeNames = new HashSet<String>();
	for (int i=0; i < grantedArray.size(); i++) {
		grantedPrivilegeNames.add(grantedArray.getString(i));
	}
	H.assertPrivilege(grantedPrivilegeNames,true,"jcr:write");

	Object deniedArray = aceObject.get("denied");
	assertNull(deniedArray);

	JsonObject aceObject2 = jsonObject.getJsonObject(testUserId2);
	assertNotNull(aceObject2);

	String principalString2 = aceObject2.getString("principal");
	assertEquals(testUserId2, principalString2);
	
	JsonArray grantedArray2 = aceObject2.getJsonArray("granted");
	assertNotNull(grantedArray2);
	assertEquals(2, grantedArray2.size());
	Set<String> grantedPrivilegeNames2 = new HashSet<String>();
	for (int i=0; i < grantedArray2.size(); i++) {
		grantedPrivilegeNames2.add(grantedArray2.getString(i));
	}
	H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:write");
	H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:lockManagement");

	Object deniedArray2 = aceObject2.get("denied");
	assertNull(deniedArray2);

}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:80,代码来源:GetAclTest.java

示例15: testEffectiveAclMergeForUser_ReplacePrivilegeOnChild

import javax.json.JsonObject; //导入方法依赖的package包/类
/**
 * Test for SLING-2600, Effective ACL servlet returns incorrect information
 */
@Test 
public void testEffectiveAclMergeForUser_ReplacePrivilegeOnChild() 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]:write", "denied"));
	
	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]:write", "granted"));
	
       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);
	assertEquals(1, grantedArray.size());
	Set<String> grantedPrivilegeNames = new HashSet<String>();
	for (int i=0; i < grantedArray.size(); i++) {
		grantedPrivilegeNames.add(grantedArray.getString(i));
	}
	H.assertPrivilege(grantedPrivilegeNames,true,"jcr:write");

	Object deniedArray = aceObject.get("denied");
	assertNull(deniedArray);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:55,代码来源:GetAclTest.java


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