本文整理汇总了Java中net.minidev.json.JSONObject.get方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.get方法的具体用法?Java JSONObject.get怎么用?Java JSONObject.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minidev.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.get方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handlePost
import net.minidev.json.JSONObject; //导入方法依赖的package包/类
public void handlePost(HttpServletRequest request, HttpServletResponse response, ITicket credentials, JSONObject jsonObject) throws ServletException, IOException {
JSONObject returnMessage = newJSONObject();
JSONObject cargo = (JSONObject)jsonObject.get(ICredentialsMicroformat.CARGO);
String message = "", rtoken="";
String verb = getVerb(jsonObject);
int code = 0;
IResult r;
System.out.println("CondoHandler.handlePost "+verb);
if (verb.equals(ITopicMapMicroformat.PUT_TOPIC)) {
//
} else {
String x = IErrorMessages.BAD_VERB+"-AdminServletPost-"+verb;
environment.logError(x, null);
throw new ServletException(x);
}
returnMessage.put(ICredentialsMicroformat.RESP_TOKEN, rtoken);
returnMessage.put(ICredentialsMicroformat.RESP_MESSAGE, message);
super.sendJSON(returnMessage.toJSONString(), code, response);
returnMessage = null; }
示例2: testEncoding2
import net.minidev.json.JSONObject; //导入方法依赖的package包/类
@Test
public void testEncoding2() throws ComponentInitializationException, AttributeEncodingException {
init();
IdPAttribute attribute = new IdPAttribute("test");
List<ByteAttributeValue> byteAttributeValues = new ArrayList<ByteAttributeValue>();
byte[] bytes = new byte[2];
bytes[0] = 0;
bytes[1] = 1;
byteAttributeValues.add(new ByteAttributeValue(bytes));
attribute.setValues(byteAttributeValues);
encoder.setAsInt(true);
JSONObject object = encoder.encode(attribute);
JSONArray array = (JSONArray)object.get("attributeName");
JSONArray arrayInts = (JSONArray)array.get(0);
Assert.assertEquals(arrayInts.get(0),0);
Assert.assertEquals(arrayInts.get(1),1);
}
示例3: handlePost
import net.minidev.json.JSONObject; //导入方法依赖的package包/类
public void handlePost(HttpServletRequest request, HttpServletResponse response, ITicket credentials, JSONObject jsonObject) throws ServletException, IOException {
JSONObject returnMessage = newJSONObject();
JSONObject cargo = (JSONObject)jsonObject.get(ICredentialsMicroformat.CARGO);
String message = "", rtoken="";
String verb = getVerb(jsonObject);
int code = 0;
IResult r;
System.out.println("CondoHandler.handlePost "+verb);
if (verb.equals(IRPGMicroformat.ADD_LEADER)) {
//TODO
} else if (verb.equals(IRPGMicroformat.ADD_MEMBER)) {
} else if (verb.equals(IRPGMicroformat.REMOVE_LEADER)) {
} else if (verb.equals(IRPGMicroformat.REMOVE_MEMBER)) {
} else {
String x = IErrorMessages.BAD_VERB+"-RPGHandler-"+verb;
environment.logError(x, null);
throw new ServletException(x);
}
returnMessage.put(ICredentialsMicroformat.RESP_TOKEN, rtoken);
returnMessage.put(ICredentialsMicroformat.RESP_MESSAGE, message);
super.sendJSON(returnMessage.toJSONString(), code, response);
returnMessage = null; }
示例4: parseJson
import net.minidev.json.JSONObject; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
private List<Object> parseJson(JSONRPC2Response response,
Class<?> clazz,
Boolean isArray) {
Gson gson = new Gson();
List objectList = new ArrayList();
if (isArray) {
JSONObject jsonObject = response.toJSONObject();
JSONArray jsonArray = (JSONArray) jsonObject.get("result");
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject item = (JSONObject) jsonArray.get(i);
objectList.add(gson.fromJson(item.toJSONString(), clazz));
}
} else {
Object modelObject = gson.fromJson(response.getResult()
.toString(), clazz);
objectList.add(modelObject);
}
return objectList;
}
示例5: executeGet
import net.minidev.json.JSONObject; //导入方法依赖的package包/类
public void executeGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String path = getPath(request);
System.out.println("UPLOADHELPERGETPATH "+path);
//{"uName":"joe","sToken":"d8611be2-1da2-4c0f-975b-d82ef1d5ce17","verb":"uUpload","uIP":""}
JSONObject jo = jsonFromString(path);
String trailer = (String)jo.get(ICredentialsMicroformat.VERB)+"/"+
(String)jo.get(ICredentialsMicroformat.USER_ID)+"/"+
(String)jo.get(ICredentialsMicroformat.SESSION_TOKEN)+"/"; //TODO add USERIP
// uUpload/joe/0628c396-5781-4451-9435-7f9a3d1ee794
String fp = FormPojo.getHtmlForm(trailer);
sendHTML(fp, response);
}
示例6: testEncodingStringArray
import net.minidev.json.JSONObject; //导入方法依赖的package包/类
@Test
public void testEncodingStringArray() throws ComponentInitializationException, AttributeEncodingException {
init();
IdPAttribute attribute = new IdPAttribute("test");
List<StringAttributeValue> stringAttributeValues = new ArrayList<StringAttributeValue>();
stringAttributeValues.add(new StringAttributeValue("value1"));
stringAttributeValues.add(new StringAttributeValue("value2"));
attribute.setValues(stringAttributeValues);
encoder.setAsArray(true);
JSONObject object = encoder.encode(attribute);
JSONArray array = (JSONArray)object.get("attributeName");
Assert.assertEquals("value1",array.get(0));
Assert.assertEquals("value2",array.get(1));
Assert.assertTrue(array.size() == 2);
}
示例7: testEncoding
import net.minidev.json.JSONObject; //导入方法依赖的package包/类
@Test
public void testEncoding() throws ComponentInitializationException, AttributeEncodingException {
init();
IdPAttribute attribute = new IdPAttribute("test");
List<ByteAttributeValue> byteAttributeValues = new ArrayList<ByteAttributeValue>();
byte[] bytes = new byte[1];
bytes[0] = 0;
byteAttributeValues.add(new ByteAttributeValue(bytes));
attribute.setValues(byteAttributeValues);
JSONObject object = encoder.encode(attribute);
String base64Coded = (String) object.get("attributeName");
Assert.assertEquals(bytes, Base64.decode(base64Coded));
}
示例8: ChangeOrg
import net.minidev.json.JSONObject; //导入方法依赖的package包/类
@Override
public UserModel ChangeOrg() {
UserModel userModel = new UserModel();
JSONObject postData = new JSONObject();
postData.put("OrgId", requestCallContext.GetUser().getOrgId());
ResponseEntity<JSONObject> jsonObjectResponseEntity = pmsRestClient.GetClient().postForEntity(requestCallContext.GetUser().getUrl() + "/Home/ChangeOrg", postData, JSONObject.class);
JSONObject body = jsonObjectResponseEntity.getBody();
if (Integer.parseInt(jsonObjectResponseEntity.getBody().get("Code").toString()) == 0) {
LinkedHashMap<String, Object> content = (LinkedHashMap<String, Object>) body.get("Content");
userModel.setSessionId(content.get("SessionId").toString());
userModel.setDefaultOrgId(content.get("DefaultOrgId").toString());
userModel.setOrgId(content.get("OrgId").toString());
userModel.setOrgName(content.get("OrgName").toString());
userModel.setOwnerId(content.get("OwnerId").toString());
userModel.setShift(content.get("Shift").toString());
userModel.setOwnerName(content.get("OwnerName").toString());
LinkedHashMap<String, Object> currentUser = (LinkedHashMap<String, Object>) content.get("CurrentUser");
userModel.setBusinessDate(currentUser.get("BusinessDate").toString());
userModel.setEmployeeName(currentUser.get("EmployeeName").toString());
String cookie = StringUtils.ToString(jsonObjectResponseEntity.getHeaders().get("Set-Cookie"));
CookieCache.Save(requestCallContext.GetUser(), cookie);
}
return userModel;
}
示例9: Login
import net.minidev.json.JSONObject; //导入方法依赖的package包/类
@Override
public UserModel Login(User user) {
ValidateUser(user);
UserModel userModel = new UserModel();
JSONObject postData = new JSONObject();
postData.put("ID", user.getUserName());
postData.put("Password", user.getPassword());
postData.put("Shift", StringUtils.isBlank(user.getShift()) ? "0" : user.getShift());
ResponseEntity<JSONObject> jsonObjectResponseEntity = pmsRestClient.GetClient().postForEntity(user.getUrl() + "/Home/Login", postData, JSONObject.class);
JSONObject body = jsonObjectResponseEntity.getBody();
if (Integer.parseInt(jsonObjectResponseEntity.getBody().get("Code").toString()) == 0) {
LinkedHashMap<String, Object> content = (LinkedHashMap<String, Object>) body.get("Content");
userModel.setSessionId(content.get("SessionId").toString());
userModel.setDefaultOrgId(content.get("DefaultOrgId").toString());
userModel.setOrgId(content.get("OrgId").toString());
userModel.setOrgName(content.get("OrgName").toString());
userModel.setOwnerId(content.get("OwnerId").toString());
userModel.setShift(content.get("Shift").toString());
userModel.setOwnerName(content.get("OwnerName").toString());
LinkedHashMap<String, Object> currentUser = (LinkedHashMap<String, Object>) content.get("CurrentUser");
userModel.setBusinessDate(currentUser.get("BusinessDate").toString());
userModel.setEmployeeName(currentUser.get("EmployeeName").toString());
user.setOrgId(Long.parseLong(currentUser.get("ExtenalOrgId").toString()));
String cookie = StringUtils.ToString(jsonObjectResponseEntity.getHeaders().get("Set-Cookie"));
CookieCache.Save(user, cookie);
}
return userModel;
}
示例10: retrieveCredential
import net.minidev.json.JSONObject; //导入方法依赖的package包/类
@Override
public JWTCredential retrieveCredential(String token) {
JWTCredential result = null;
try {
JWSObject jws = JWSObject.parse(token);
String apiKey = jws.getHeader().getKeyID();
if (apiKey != null && keys.contains(apiKey)) {
RSAKey rsaKey = (RSAKey) jwkSet.getKeyByKeyId(apiKey).toPublicJWK();
JWSVerifier verifier = new RSASSAVerifier(rsaKey);
if (jws.verify(verifier)) {
JWTClaimsSet claimsSet = JWTClaimsSet.parse(jws.getPayload().toJSONObject());
// Verify time validity of token.
Date creationTime = claimsSet.getIssueTime();
Date expirationTime = claimsSet.getExpirationTime();
Date now = new Date();
long validityPeriod = expirationTime.getTime() - creationTime.getTime();
if (creationTime.before(now) && now.before(expirationTime) && validityPeriod < 120000 /*2 minutes*/) {
JSONObject realmAccess = (JSONObject) claimsSet.getClaim("realm_access");
JSONArray rolesArray = (JSONArray) realmAccess.get("roles");
Set<String> roles = new HashSet<>();
rolesArray.forEach(r -> roles.add(r.toString()));
result = new JWTCredential(claimsSet.getSubject(), roles);
}
}
}
} catch (ParseException | JOSEException e) {
; // Token is not valid
}
return result;
}
示例11: loadConfigHierarchy
import net.minidev.json.JSONObject; //导入方法依赖的package包/类
private void loadConfigHierarchy() throws Exception {
if (resource != null && bundle != null) {
String key = resource.getPath();
if (USE_CACHE_FOR_CONFIGURATION && configCache.containsKey(key)) {
configMembers = configCache.get(key);
} else {
ExtendedNodeType extendedNodeType = resource.getNode().getPrimaryNodeType();
Map<String, ExtendedNodeType> map = getAllNodeTypesForNode(extendedNodeType, new LinkedHashMap<String, ExtendedNodeType>());
if ( map.size() > 0 ){
for (String keyMap : map.keySet()){
ExtendedNodeType nodeTypeToEvaluate = map.get(keyMap);
JSONObject xkConfigJSONObj = getJSON( nodeTypeToEvaluate );
if (xkConfigJSONObj != null) {
Map<String, InertProperty> propsMap = new LinkedHashMap<>();
for (String jsonKey : xkConfigJSONObj.keySet()) {
Object object = xkConfigJSONObj.get(jsonKey);
InertProperty property = new InertProperty(jsonKey, object);
propsMap.put(jsonKey, property);
}
configMembers.put(keyMap, propsMap);
} else {
// TODO review if LOG is needed here or not.
// LOG.error(LOG_PRE + "Not able to load file into JSON Object: {}, check your configuration node",nodeTypeToEvaluate);
}
}
if (USE_CACHE_FOR_CONFIGURATION) {
configCache.put(key, configMembers);
}
}
}
}
propNamesDeepCache = names(false);
}
示例12: process
import net.minidev.json.JSONObject; //导入方法依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, TemplateContentModel contentModel)
throws ProcessException {
try {
// Add page path references
if (contentModel.has(ITEM_LIST_KEY_NAME)) {
Object pathRefs = contentModel.get(ITEM_LIST_KEY_NAME);
Collection<Map<String, Object>> pathList = new ArrayList<>();
String currentPage = contentModel.getAsString(PAGE + DOT + PATH);
if (pathRefs instanceof Collection) {
for(Object pathRef : (Collection<Object>) pathRefs) {
JSONObject pagePath = new JSONObject();
String path = "";
if (pathRef instanceof String) {
path = pathRef.toString();
} else if (pathRef instanceof JSONObject) {
JSONObject a = (JSONObject) pathRef;
Object value = a.get(PATH);
if ( value != null ) {
path = value.toString();
}
}
if (!path.equals(currentPage)) {
pagePath.put(PATH, path);
pathList.add(pagePath);
} else if (!(contentModel.has(REMOVE_CURRENT_PAGE_PATH_CONFIG_KEY)
&& contentModel.getAsString(REMOVE_CURRENT_PAGE_PATH_CONFIG_KEY).equals(TRUE))){
pagePath.put(IS_CURRENT_PAGE, true);
pagePath.put(PATH, path);
pathList.add(pagePath);
}
}
}
contentModel.set(LIST_PROPERTIES_KEY + DOT + PAGEREFS_CONTENT_KEY_NAME, pathList);
}
} catch (Exception e) {
throw new ProcessException(e);
}
}
示例13: getGeoCode
import net.minidev.json.JSONObject; //导入方法依赖的package包/类
@Override
public Map<String, BigDecimal> getGeoCode(String state, String country) throws Exception {
Map<String,BigDecimal> geocode = new HashMap<String,BigDecimal>();
// validate input
if(country != null && !country.isEmpty()) {
StringBuilder address = new StringBuilder();
if (state != null && !state.isEmpty()) {
address.append(state);
address.append(",");
}
String countryCode = CountryCodeConverterUtil.convertToIso2(country);
address.append(countryCode);
try {
URL url = getRequestUrl(address.toString());
String response = getResponse(url);
if(response != null) {
Object obj = JSONValue.parse(response);
if(obj instanceof JSONObject) {
JSONObject jsonObject = (JSONObject) obj;
JSONArray array = (JSONArray) jsonObject.get("results");
JSONObject element = (JSONObject) array.get(0);
JSONObject geometry = (JSONObject) element.get("geometry");
JSONObject location = (JSONObject) geometry.get("location");
Double lng = (Double) location.get("lng");
Double lat = (Double) location.get("lat");
geocode.put("lng", new BigDecimal(lng));
geocode.put("lat", new BigDecimal(lat));
}
return geocode;
} else {
throw new Exception("Fail to convert to geocode");
}
}
catch(Exception ex) {
throw new Exception(ex.getMessage());
}
}
return geocode;
}
示例14: process
import net.minidev.json.JSONObject; //导入方法依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, TemplateContentModel contentModel)
throws ProcessException {
try {
Resource resource = (Resource) executionContext.get(JAHIA_RESOURCE);
RenderContext renderContext = (RenderContext) executionContext.get(JAHIA_RENDER_CONTEXT);
// Add page path references
if (contentModel.has(ITEM_LIST_KEY_NAME)) {
Object pathRefs = contentModel.get(ITEM_LIST_KEY_NAME);
Collection<Map<String, Object>> pathList = new ArrayList<>();
String currentPage = contentModel.getAsString(PAGE + DOT + PATH);
if (pathRefs instanceof Collection) {
for(Object pathRef : (Collection<Object>) pathRefs) {
JSONObject pagePath = new JSONObject();
String path = "";
if (pathRef instanceof String) {
path = ResourceUtils.getPathFromURL(pathRef.toString(), renderContext);
} else if (pathRef instanceof JSONObject) {
JSONObject a = (JSONObject) pathRef;
Object value = a.get(PATH);
if ( value != null ) {
path = ResourceUtils.getPathFromURL(value.toString(), renderContext);
}
}
if (!path.equals(currentPage)) {
pagePath.put(PATH, path);
pathList.add(pagePath);
} else if (!(contentModel.has(REMOVE_CURRENT_PAGE_PATH_CONFIG_KEY)
&& contentModel.getAsString(REMOVE_CURRENT_PAGE_PATH_CONFIG_KEY).equals(TRUE))){
pagePath.put(IS_CURRENT_PAGE, true);
pagePath.put(PATH, path);
pathList.add(pagePath);
}
}
}
contentModel.set(LIST_PROPERTIES_KEY + DOT + PAGEREFS_CONTENT_KEY_NAME, pathList);
}
} catch (Exception e) {
throw new ProcessException(e);
}
}