List of usage examples for org.json.simple JSONObject containsKey
boolean containsKey(Object key);
From source file:com.serena.rlc.provider.artifactory.domain.ArtifactoryObject.java
public static Object getJSONValue(JSONObject obj, String key) { Object retObj = null;//from www.jav a 2s. c o m if (obj.containsKey(key)) { return obj.get(key); } return retObj; }
From source file:me.cybermaxke.merchants.v16r3.SUtil.java
private static void apply(Object element, Data data) { if (!(element instanceof JSONObject) && !(element instanceof JSONArray)) { return;//from w w w . ja v a2s.c o m } ChatColor lastColor0 = data.lastColor; Set<ChatColor> lastStyles0 = Sets.newHashSet(data.lastStyles); if (element instanceof JSONObject) { JSONObject object = (JSONObject) element; if (object.containsKey("color")) { ChatColor color = lookupColors.get(object.get("color")); if (color != null) { if (data.lastColor != color) { data.builder.append(color); } } } for (Entry<String, ChatColor> style : lookupStyles.entrySet()) { String key = style.getKey(); ChatColor value = style.getValue(); if (object.containsKey(key)) { if (data.lastStyles.add(value)) { data.builder.append(value); } } else { data.lastStyles.remove(value); } } if (object.containsKey("extra")) { apply(object.get("extra"), data); } } else if (element instanceof JSONArray) { JSONArray array = (JSONArray) element; for (Object object0 : array) { apply(object0, data); } } data.lastColor = lastColor0; data.lastStyles = lastStyles0; }
From source file:at.ac.tuwien.dsg.smartcom.integration.JSONConverter.java
private static String[][] parsePeerInfoResults(JSONObject json) { if (json.containsKey("results")) { JSONArray array = (JSONArray) json.get("results"); if (array.size() == 0) { return null; }//from www . j av a 2 s. c om List<String[]> outerList = new ArrayList<>(); for (Object o : array) { JSONArray innerArray = (JSONArray) o; List<String> valueList = new ArrayList<>(); for (Object ob : innerArray) { try { valueList.add(parseToString(ob)); } catch (ConverterException e) { return null; } } outerList.add(valueList.toArray(new String[valueList.size()])); } return outerList.toArray(new String[outerList.size()][]); } else { return null; } }
From source file:fr.bmartel.protocol.google.oauth.device.OauthForDeviceResponse.java
/** * convert json object api response to oaut device response java object * //from w ww . ja va 2 s. c o m * @param response * @return */ public static OauthForDeviceResponse decodeOauthForDeviceResponse(JSONObject response) { if (response != null) { if (response.containsKey(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_DEVICE_CODE) && response.containsKey(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_USER_CODE) && response.containsKey(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_VERIFICATION_URL) && response.containsKey(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_EXPIRING) && CommonUtils .isInteger(response.get(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_EXPIRING).toString()) && response.containsKey(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_INTERVAL) && CommonUtils.isInteger( response.get(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_INTERVAL).toString())) { // build oauth device response return new OauthForDeviceResponse( response.get(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_DEVICE_CODE).toString(), response.get(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_USER_CODE).toString(), response.get(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_VERIFICATION_URL).toString(), Integer.parseInt( response.get(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_EXPIRING).toString()), Integer.parseInt( response.get(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_INTERVAL).toString())); } } return null; }
From source file:com.rmtheis.yandtran.YandexTranslatorAPI.java
private static String[] jsonArrToStringArr(final String inputString, final String propertyName) throws Exception { final JSONArray jsonArr = (JSONArray) JSONValue.parse(inputString); String[] values = new String[jsonArr.size()]; int i = 0;//from ww w . ja v a 2 s . co m for (Object obj : jsonArr) { if (propertyName != null && propertyName.length() != 0) { final JSONObject json = (JSONObject) obj; if (json.containsKey(propertyName)) { values[i] = json.get(propertyName).toString(); } } else { values[i] = obj.toString(); } i++; } return values; }
From source file:net.amigocraft.mpt.command.RemoveCommand.java
public static void removePackage(String id) throws MPTException { if (Thread.currentThread().getId() == Main.mainThreadId) throw new MPTException(ERROR_COLOR + "Packages may not be removed from the main thread!"); id = id.toLowerCase();/*w ww . jav a 2 s. c o m*/ if (((JSONObject) Main.packageStore.get("packages")).containsKey(id)) { JSONObject pack = (JSONObject) ((JSONObject) Main.packageStore.get("packages")).get(id); if (pack.containsKey("installed")) { lockStores(); if (pack.containsKey("files")) { for (Object e : (JSONArray) pack.get("files")) { File f = new File(Bukkit.getWorldContainer(), e.toString()); if (f.exists()) { if (!f.delete()) { if (VERBOSE) { Main.log.warning("Failed to delete file " + f.getName()); } } else { checkParent(f); } } } pack.remove("files"); } else Main.log.warning("No file listing for package " + id + "!"); File archive = new File(Main.plugin.getDataFolder(), "cache" + File.separator + id + ".zip"); if (archive.exists()) { if (!archive.delete() && VERBOSE) { Main.log.warning("Failed to delete archive from cache"); } } pack.remove("installed"); try { writePackageStore(); } catch (IOException ex) { unlockStores(); throw new MPTException(ERROR_COLOR + "Failed to save changes to disk!"); } unlockStores(); } else throw new MPTException( ERROR_COLOR + "Package " + ID_COLOR + id + ERROR_COLOR + " is not installed!"); } else throw new MPTException(ERROR_COLOR + "Cannot find package with id " + ID_COLOR + id); unlockStores(); }
From source file:net.amigocraft.mpt.command.UpgradeCommand.java
/** * Attempts to upgrade a package by the given ID * <strong>This method may not be called from the main thread.</strong> * @param id the ID of the package to upgrade * @return the new version, or null if the package was not upgraded * @throws MPTException if called from the main thread, or if something goes wrong while upgrading *//*from w ww .j a v a2s . com*/ public static String upgradePackage(String id) throws MPTException { if (Thread.currentThread().getId() == Main.mainThreadId) throw new MPTException(ERROR_COLOR + "Packages may not be upgraded from the main thread!"); id = id.toLowerCase(); if (Main.packageStore.containsKey("packages") && ((JSONObject) Main.packageStore.get("packages")).containsKey(id)) { JSONObject pack = (JSONObject) ((JSONObject) Main.packageStore.get("packages")).get(id); if (pack.containsKey("installed")) { if (pack.containsKey("version")) { int diff = compareVersions(pack.get("installed").toString(), pack.get("version").toString()); if (diff > 0) { // easy way out RemoveCommand.removePackage(id); InstallCommand.downloadPackage(id); InstallCommand.installPackage(id); return pack.get("version").toString(); } else // up-to-date return null; } else throw new MPTException(ERROR_COLOR + "Package " + ID_COLOR + id + ERROR_COLOR + " is missing version string! Type " + COMMAND_COLOR + "/mpt update" + ERROR_COLOR + " to fix this."); } else throw new MPTException( ERROR_COLOR + "Package " + ID_COLOR + id + ERROR_COLOR + " is not installed!"); } return null; }
From source file:at.ac.tuwien.dsg.smartcom.integration.JSONConverter.java
private static String[] parseResults(JSONObject json) { List<String> valueList = new ArrayList<>(); if (json.containsKey("results")) { JSONArray array = (JSONArray) json.get("results"); for (Object obj : array) { JSONArray innerArray = (JSONArray) obj; for (Object o : innerArray) { try { valueList.add(parseToString(o)); } catch (ConverterException e) { return null; }/*from w ww. ja v a 2 s.co m*/ } } return valueList.toArray(new String[valueList.size()]); } else { return null; } }
From source file:hoot.services.controllers.job.JobControllerBase.java
static String getParameterValue(String key, JSONArray args) { for (Object arg : args) { JSONObject o = (JSONObject) arg; if (o.containsKey(key)) { return o.get(key).toString(); }//ww w. j av a 2 s . c om } return null; }
From source file:eu.dety.burp.joseph.utilities.Converter.java
/** * Get RSA PublicKey by JWK JSON input// w w w . j av a 2 s .com * * @param input * JSON Web Key {@link JSONObject} * @return {@link PublicKey} or null */ private static PublicKey getRsaPublicKeyByJwk(JSONObject input) { if (!input.containsKey("kty")) return null; String kty = (String) input.get("kty"); if (kty.equals("RSA")) return buildRsaPublicKeyByJwk(input); return null; }