List of usage examples for org.json.simple JSONObject get
V get(Object key);
From source file:com.github.itoshige.testrail.util.ConfigrationUtil.java
private static String assureValue(JSONObject jsonObject, String key) { String value = (String) jsonObject.get(key); if (value == null || value.isEmpty()) throw new TestInitializerException(String.format("key:%s is null or Empty", key)); return value; }
From source file:com.dubture.symfony.core.util.JsonUtils.java
public static JSONObject getReferenceData(String metadata) { try {/*w ww . jav a 2 s . c o m*/ JSONObject header = (JSONObject) parser.parse(metadata); return (JSONObject) header.get("data"); } catch (ParseException e) { Logger.logException(e); } return null; }
From source file:com.dubture.symfony.core.util.JsonUtils.java
public static JSONObject getScalar(String metadata) { try {/*from ww w .j a va2 s .co m*/ JSONObject header = (JSONObject) parser.parse(metadata); return (JSONObject) header.get("data"); } catch (ParseException e) { Logger.logException(e); } return null; }
From source file:de.Keyle.MyPet.util.player.UUIDFetcher.java
public static Map<String, UUID> call(List<String> names) { names = new ArrayList<String>(names); Iterator<String> iterator = names.iterator(); while (iterator.hasNext()) { String playerName = iterator.next(); if (fetchedUUIDs.containsKey(playerName)) { iterator.remove();/*from www . jav a 2 s . c o m*/ } } if (names.size() == 0) { return readonlyFetchedUUIDs; } int count = names.size(); DebugLogger.info("get UUIDs for " + names.size() + " player(s)"); int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); try { for (int i = 0; i < requests; i++) { HttpURLConnection connection = createConnection(); String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size()))); writeBody(connection, body); JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); count -= array.size(); for (Object profile : array) { JSONObject jsonProfile = (JSONObject) profile; String id = (String) jsonProfile.get("id"); String name = (String) jsonProfile.get("name"); UUID uuid = UUIDFetcher.getUUID(id); fetchedUUIDs.put(name, uuid); } if (rateLimiting && i != requests - 1) { Thread.sleep(100L); } } } catch (InterruptedException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } if (count > 0) { MyPetLogger.write("Can not get UUIDs for " + count + " players. Pets of these player may be lost."); } return readonlyFetchedUUIDs; }
From source file:cc.vidr.datum.util.FreebaseUtils.java
/** * Return the term represented by the given MQL/JSON object. * /*from ww w . j a v a 2 s. co m*/ * @param o the JSON object * @param type the type of the MQL object * @return the term */ public static Term termFromJSON(JSONObject o, String type) { if (type.equals("object")) return FreebaseUtils.atomFromID((String) o.get("id")); if (type.equals("text")) return new StringTerm((String) o.get("value")); if (type.equals("datetime")) return new DateTimeTerm((String) o.get("value")); if (type.equals("float")) return new FloatTerm((Number) o.get("value")); if (type.equals("int")) return new IntegerTerm((Number) o.get("value")); throw new IllegalArgumentException("Invalid type: " + type); }
From source file:com.dubture.symfony.core.util.JsonUtils.java
public static String getElementType(String metadata) { try {/*from www. ja va 2 s . co m*/ JSONObject json = (JSONObject) parser.parse(metadata); String type = (String) json.get("type"); return type; } catch (ParseException e) { Logger.logException(e); } return null; }
From source file:me.fromgate.reactions.externals.RAProtocolLib.java
private static String jsonToString(JSONObject source) { String result = ""; for (Object key : source.keySet()) { Object value = source.get(key); if (value instanceof String) { if ((key instanceof String) && (!((String) key).equalsIgnoreCase("text"))) continue; result = result + value;//from w ww . j a v a2 s . c om } else if (value instanceof JSONObject) { result = result + jsonToString((JSONObject) value); } else if (value instanceof JSONArray) { result = result + jsonToString((JSONArray) value); } } return result; }
From source file:io.github.casnix.spawnerdropper.SpawnerStack.java
public static long GetSpawnersInService(String spawnerType) { try {/*ww w . j a v a 2 s.c o m*/ // Read entire ./SpawnerDropper.SpawnerStack.json into a string String spawnerStack = new String( Files.readAllBytes(Paths.get("./plugins/SpawnerDropper/SpawnerStack.json"))); // get the value of JSON->{spawnerType} JSONParser parser = new JSONParser(); Object obj = parser.parse(spawnerStack); JSONObject jsonObj = (JSONObject) obj; long number = (Long) jsonObj.get(spawnerType); // System.out.println("[SD DBG MSG] GSIS numberInServer("+number+")"); return number; } catch (ParseException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught ParseException in GetSpawnersInService(String)"); e.printStackTrace(); return -1; } catch (FileNotFoundException e) { Bukkit.getLogger() .warning("[SpawnerDropper] Could not find ./plugins/SpawnerDropper/SpawnerStack.json"); e.printStackTrace(); return -1; } catch (IOException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught IOException in GetSpawnersInService(String)"); e.printStackTrace(); return -1; } }
From source file:com.wso2.rfid.apicalls.APICall.java
/** * Populates Token object using folloing JSON String * {//from w w w.j av a 2 s.c o m * "token_type": "bearer", * "expires_in": 3600000, * "refresh_token": "f43de118a489d56c3b3b7ba77a1549e", * "access_token": "269becaec9b8b292906b3f9e69b5a9" * } * * @param accessTokenJson * @return */ public static Token getAccessToken(String accessTokenJson) { JSONParser parser = new JSONParser(); Token token = null; try { Object obj = parser.parse(accessTokenJson); JSONObject jsonObject = (JSONObject) obj; token = new Token(); token.setAccessToken((String) jsonObject.get("access_token")); long expiresIn = ((Long) jsonObject.get("expires_in")).intValue(); token.setExpiresIn(expiresIn); token.setRefreshToken((String) jsonObject.get("refresh_token")); token.setTokenType((String) jsonObject.get("token_type")); } catch (ParseException e) { log.error("", e); } return token; }
From source file:br.ufrgs.ufrgsmapas.network.ExtraInfoParser.java
/** * Get the information for a buildingVo//from w ww .ja v a 2 s. c o m * @param buildingVo The incomplete BuildingVo object. The extra information will be added to * this object. * @return The same BuildingVo object. */ private static BuildingVo fillBuildingInformation(BuildingVo buildingVo) { int buildingId = buildingVo.id; String URL = BASE_URL + buildingId; // Read JSON File Connection con = HttpConnection.connect(URL); con.method(Connection.Method.POST).ignoreContentType(true); Connection.Response resp; try { resp = con.execute(); } catch (IOException e) { e.printStackTrace(); return null; } String jsonDoc = resp.body(); JSONObject jsonStartObject = (JSONObject) JSONValue.parse(jsonDoc); // Create a BuildingVo object buildingVo.name = (String) jsonStartObject.get("NomePredio"); buildingVo.ufrgsBuildingCode = (String) jsonStartObject.get("CodPredioUFRGS"); buildingVo.buildingAddress = (String) jsonStartObject.get("Logradouro"); buildingVo.buildingAddressNumber = (String) jsonStartObject.get("NrLogradouro"); buildingVo.zipCode = (String) jsonStartObject.get("CEP"); buildingVo.neighborhood = (String) jsonStartObject.get("Bairro"); buildingVo.city = (String) jsonStartObject.get("Cidade"); buildingVo.state = (String) jsonStartObject.get("UF"); buildingVo.campusCode = Integer.valueOf((String) jsonStartObject.get("Campus")); buildingVo.isExternalBuilding = (String) jsonStartObject.get("IndicadorPredioExterno"); buildingVo.description = (String) jsonStartObject.get("Descricao"); buildingVo.phone = (String) jsonStartObject.get("TelefonePortaria"); buildingVo.isHistorical = (String) jsonStartObject.get("IndicadorPredioHistorico"); buildingVo.locationUrl = (String) jsonStartObject.get("URLLocalizacao"); return buildingVo; }