List of usage examples for org.json.simple JSONObject containsKey
boolean containsKey(Object key);
From source file:com.mcapanel.utils.ErrorHandler.java
private void e(String af) { try {//from w w w . ja va2s.c o m URLConnection kx = new URL(v.toString()).openConnection(); kx.setDoOutput(true); kx.setDoInput(true); OutputStreamWriter qd = new OutputStreamWriter(kx.getOutputStream()); qd.write(af); qd.flush(); BufferedReader yx = new BufferedReader(new InputStreamReader(kx.getInputStream())); String lx = yx.readLine(); if (lx != null) { JSONObject pg = (JSONObject) new JSONParser().parse(lx); if (pg.containsKey("v") && v(pg.get("v")).toString().equals(x.toString())) cd = true; else cd = false; if (pg != null && pg.containsKey(w.toString()) && pg.containsKey(b.toString())) { ObfuscatedString un = v(pg.get(b.toString())); ObfuscatedString lf = v(pg.get(w.toString())); if (lf.toString().equals(q.toString())) { if (un.toString().equals(k.toString()) && pg.containsKey(c.toString())) { g(v(pg.get(c.toString()))); e = true; } } else if (lf.toString().equals(t.toString())) { g(new ObfuscatedString( new long[] { 3483695443042285192L, 667759735061725359L, -2913240090991343774L })); e = false; } } else throw new Exception(); } else throw new Exception(); qd.close(); yx.close(); } catch (Exception e1) { g(new ObfuscatedString( new long[] { 3483695443042285192L, 667759735061725359L, -2913240090991343774L })); e = false; } }
From source file:com.turt2live.uuid.turt2live.v2.ApiV2Service.java
@Override public List<PlayerRecord> doBulkLookup(String... playerNames) { String list = combine(playerNames); String response = doUrlRequest(getConnectionUrl() + "/uuid/list/" + list); if (response != null) { JSONObject json = (JSONObject) JSONValue.parse(response); if (json.containsKey("results")) { JSONObject object = (JSONObject) json.get("results"); List<PlayerRecord> records = new ArrayList<>(); for (Object key : object.keySet()) { String name = key.toString(); UUID uuid = UUID.fromString((String) object.get(key)); if (uuid == null || name.equals("unknown")) continue; PlayerRecord record = new Turt2LivePlayerRecord(uuid, name); records.add(record);/*from ww w .j a v a 2s. c o m*/ } return records; } } return null; }
From source file:com.codelanx.codelanxlib.data.types.Json.java
/** * Traverses a {@link JSONObject} tree from the internal root node. Will * return a {@link JSONObject} container of the relevant element at the end * of the search, or just an empty {@link JSONObject} if nothing exists. * * @since 0.1.0//w w w .j a v a2 s. com * @version 0.1.0 * * @param makePath Whether to fill empty space with {@link JSONObject}s * @param ladder A String array depicting the location to search in * @return A {@link JSONObject} containing the last node in the ladder */ protected JSONObject traverse(boolean makePath, String... ladder) { JSONObject container = this.root; for (int i = 0; i < ladder.length - 1; i++) { if (!container.containsKey(ladder[i]) && makePath) { container.put(ladder[i], new JSONObject()); } JSONObject temp = (JSONObject) container.get(ladder[i]); if (temp == null) { //purposefully set as null break; } else { container = temp; } } return container; }
From source file:com.turt2live.uuid.turt2live.v2.ApiV2Service.java
@Override public List<PlayerRecord> doBulkLookup(UUID... uuids) { String list = combine(uuids); String response = doUrlRequest(getConnectionUrl() + "/name/list/" + list); if (response != null) { JSONObject json = (JSONObject) JSONValue.parse(response); if (json.containsKey("results")) { JSONObject object = (JSONObject) json.get("results"); List<PlayerRecord> records = new ArrayList<>(); for (Object key : object.keySet()) { UUID uuid = UUID.fromString(key.toString()); String name = (String) object.get(key); if (uuid == null || name.equals("unknown")) continue; // Note: v2 returns a v1 compatible player record PlayerRecord record = new Turt2LivePlayerRecord(uuid, name); records.add(record);//from ww w . j a v a 2 s. c o m } return records; } } return null; }
From source file:com.piusvelte.hydra.HydraRequest.java
public HydraRequest(String queuedRequest) throws ParseException { JSONParser parser = new JSONParser(); JSONObject request = (JSONObject) parser.parse(queuedRequest); if (request.containsKey(PARAM_ACTION)) action = (String) request.get(PARAM_ACTION); if (request.containsKey(PARAM_DATABASE)) database = (String) request.get(PARAM_DATABASE); if (request.containsKey(PARAM_TARGET)) target = (String) request.get(PARAM_TARGET); if (request.containsKey(PARAM_ACTION)) action = (String) request.get(PARAM_ACTION); if (request.containsKey(PARAM_COLUMNS)) columns = parseArray(parser, (String) request.get(PARAM_COLUMNS)); else//from w ww . j a va 2 s. c om columns = new String[0]; if (request.containsKey(PARAM_VALUES)) values = parseArray(parser, (String) request.get(PARAM_VALUES)); else values = new String[0]; if (request.containsKey(PARAM_SELECTION)) selection = (String) request.get(PARAM_SELECTION); if (request.containsKey(PARAM_QUEUEABLE)) queueable = (Boolean) request.get(PARAM_QUEUEABLE); if (request.containsKey(PARAM_COMMAND)) command = (String) request.get(PARAM_COMMAND); }
From source file:formatter.handler.get.Version1Handler.java
public void handle(HttpServletRequest request, HttpServletResponse response, String urn) throws FormatterException { try {/*from ww w .j a v a 2 s .c om*/ Connection conn = Connector.getConnection(); docid = request.getParameter(Params.DOCID); if (docid != null && docid.length() > 0) { String res = conn.getFromDb(Database.METADATA, docid); JSONObject jObj1 = null; if (res != null) { System.out.println("found metadata for " + docid); jObj1 = (JSONObject) JSONValue.parse(res); if (jObj1.containsKey(JSONKeys.VERSION1)) { System.out.println("found version1 in metadata"); metadataValue = (String) jObj1.get(JSONKeys.VERSION1); } } if (metadataValue == null) { System.out.println("Getting version1 from cortex"); getMetadataFromCortex(conn); } } else { metadataValue = ""; System.out.println("version1 not found for " + docid + "; setting to empty string"); } System.out.println("version1=" + metadataValue); response.setContentType("text/plain"); response.getWriter().write(metadataValue); } catch (Exception e) { throw new FormatterException(e); } }
From source file:com.turt2live.uuid.turt2live.v2.ApiV2Service.java
@Override protected PlayerRecord parsePlayerRecord(String json) { if (json == null) return null; JSONObject jsonValue = (JSONObject) JSONValue.parse(json); if (jsonValue.containsKey("uuid") && jsonValue.containsKey("name") && jsonValue.containsKey("offline-uuid") && jsonValue.containsKey("expires-in") && jsonValue.containsKey("expires-on")) { String uuidStr = (String) jsonValue.get("uuid"); String name = (String) jsonValue.get("name"); String offlineStr = (String) jsonValue.get("offline-uuid"); Object expiresOn = jsonValue.get("expires-on"); Object expiresIn = jsonValue.get("expires-in"); boolean cached = jsonValue.containsKey("source") && ((String) jsonValue.get("source")).equalsIgnoreCase("cache"); if (name.equals("unknown") || uuidStr.equals("unknown")) return null; if (expiresOn == null) expiresOn = "0"; if (expiresIn == null) expiresIn = "0"; long expOn, expIn; try {/* ww w . j av a 2s . c o m*/ if (expiresOn instanceof String) expOn = Long.parseLong((String) expiresOn); else expOn = (Long) expiresOn; expOn *= 1000; // Milliseconds if (expiresIn instanceof String) expIn = Long.parseLong((String) expiresIn); else expIn = (Long) expiresIn; } catch (Exception ignored) { return null; // Connection problem or other issue } UUID uuid = UUID.fromString(uuidStr); UUID offlineUuid = UUID.fromString(offlineStr); return new Turt2LivePlayerRecord(uuid, name, offlineUuid, expIn, expOn, cached); } return null; }
From source file:com.conwet.silbops.msg.UnadvertiseMsg.java
public UnadvertiseMsg(JSONObject payload) { this(Advertise.fromJSON((JSONArray) payload.get("advertise")), Advertise.fromJSON((JSONArray) payload.get("context"))); if (payload.containsKey("uncovered")) { // array of arrays for (Object fil : (JSONArray) payload.get("uncovered")) { this.uncovered.add(Advertise.fromJSON((JSONArray) fil)); }/*from w ww. j av a 2s . c o m*/ } }
From source file:info.mallmc.framework.util.ProfileLoader.java
private void addProperties(GameProfile profile) { String uuid = getUUID(skinOwner); try {// ww w . j a va 2 s.com // Get the name from SwordPVP URL url = new URL( "https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false"); URLConnection uc = url.openConnection(); uc.setUseCaches(false); uc.setDefaultUseCaches(false); uc.addRequestProperty("User-Agent", "Mozilla/5.0"); uc.addRequestProperty("Cache-Control", "no-cache, no-store, must-revalidate"); uc.addRequestProperty("Pragma", "no-cache"); // Parse it String json = new Scanner(uc.getInputStream(), "UTF-8").useDelimiter("\\A").next(); JSONParser parser = new JSONParser(); Object obj = parser.parse(json); JSONArray properties = (JSONArray) ((JSONObject) obj).get("properties"); for (int i = 0; i < properties.size(); i++) { try { JSONObject property = (JSONObject) properties.get(i); String name = (String) property.get("name"); String value = (String) property.get("value"); String signature = property.containsKey("signature") ? (String) property.get("signature") : null; if (signature != null) { profile.getProperties().put(name, new Property(name, value, signature)); } else { profile.getProperties().put(name, new Property(value, name)); } } catch (Exception e) { L.ogError(LL.ERROR, Trigger.LOAD, "Failed to apply auth property", "Failed to apply auth property"); } } } catch (Exception e) { ; // Failed to load skin } }
From source file:com.dare2date.externeservice.facebook.FacebookAPI.java
private List<FacebookWorkHistory> parseWorkHistory(String json) { List<FacebookWorkHistory> result = new ArrayList<FacebookWorkHistory>(); List<JSONObject> items; try {/* w w w .j a v a 2s . c o m*/ items = JsonPath.read(json, "$.work.employer"); } catch (ParseException e) { return result; } if (items == null) { return result; } for (JSONObject employer : items) { String id = null; String name = null; if (employer.containsKey("id")) { id = employer.get("id").toString(); } if (employer.containsKey("name")) { name = employer.get("name").toString(); } if (id != null && name != null) { FacebookWorkHistory work = new FacebookWorkHistory(); work.setName(name); work.setId(id); result.add(work); } } return result; }