List of usage examples for org.json.simple JSONObject get
V get(Object key);
From source file:com.jql.gcmccsmock.GCMMessageHandler.java
/** * Create Ack Message/* w w w . j a va2s . c o m*/ <message id=""> <gcm xmlns="google:mobile:data"> { "from":"REGID", "message_id":"m-1366082849205" "message_type":"ack" } </gcm> </message> * @param original * @param jsonObject * @return * @throws EntityFormatException */ private static Stanza createAckMessageStanza(Stanza original, JSONObject jsonObject) throws EntityFormatException { Map<String, Object> message = new HashMap<>(); message.put(JSON_MESSAGE_TYPE, JSON_ACK); message.put(JSON_FROM, jsonObject.get(JSON_TO)); message.put(JSON_MESSAGE_ID, jsonObject.get(JSON_MESSAGE_ID)); String payload = JSONValue.toJSONString(message); // no from & to StanzaBuilder builder = new StanzaBuilder("message"); builder.addAttribute("id", original.getAttributeValue("id") == null ? "" : original.getAttributeValue("id")); GCMMessage.Builder gcmMessageBuilder = new GCMMessage.Builder(); gcmMessageBuilder.addText(payload); builder.addPreparedElement(gcmMessageBuilder.build()); return builder.build(); }
From source file:net.amigocraft.mpt.util.MiscUtil.java
public static JSONObject getRemoteIndex(String path) throws MPTException { try {//www . j a v a 2s.c o m URL url = new URL(path + (!path.endsWith("/") ? "/" : "") + "mpt.json"); // get URL object for data file URLConnection conn = url.openConnection(); if (conn instanceof HttpURLConnection) { HttpURLConnection http = (HttpURLConnection) conn; // cast the connection int response = http.getResponseCode(); // get the response if (response >= 200 && response <= 299) { // verify the remote isn't upset at us InputStream is = http.getInputStream(); // open a stream to the URL BufferedReader reader = new BufferedReader(new InputStreamReader(is)); // get a reader JSONParser parser = new JSONParser(); // get a new parser String line; StringBuilder content = new StringBuilder(); while ((line = reader.readLine()) != null) content.append(line); JSONObject json = (JSONObject) parser.parse(content.toString()); // parse JSON object // vefify remote config is valid if (json.containsKey("packages") && json.get("packages") instanceof JSONObject) { return json; } else throw new MPTException( ERROR_COLOR + "Index for repository at " + path + "is missing required elements!"); } else { String error = ERROR_COLOR + "Remote returned bad response code! (" + response + ")"; if (!http.getResponseMessage().isEmpty()) error += " The remote says: " + ChatColor.GRAY + ChatColor.ITALIC + http.getResponseMessage(); throw new MPTException(error); } } else throw new MPTException(ERROR_COLOR + "Bad protocol for URL!"); } catch (MalformedURLException ex) { throw new MPTException(ERROR_COLOR + "Cannot parse URL!"); } catch (IOException ex) { throw new MPTException(ERROR_COLOR + "Cannot open connection to URL!"); } catch (ParseException ex) { throw new MPTException(ERROR_COLOR + "Repository index is not valid JSON!"); } }
From source file:com.jql.gcmccsmock.GCMMessageHandler.java
/** * Create Bad RegId Nack Message Stanza/* www . j a v a 2 s . c o m*/ * <message> <gcm xmlns="google:mobile:data"> { "message_type":"nack", "message_id":"msgId1", "from":"SomeInvalidRegistrationId", "error":"BAD_REGISTRATION", "error_description":"Invalid token on 'to' field: SomeInvalidRegistrationId" } </gcm> </message> * @param original * @param jsonObject * @return * @throws EntityFormatException */ private static Stanza createNackBadRegIdMessageStanza(Stanza original, JSONObject jsonObject) throws EntityFormatException { Map<String, Object> message = new HashMap<>(); message.put(JSON_MESSAGE_TYPE, JSON_NACK); message.put(JSON_FROM, jsonObject.get(JSON_TO)); message.put(JSON_MESSAGE_ID, jsonObject.get(JSON_MESSAGE_ID)); message.put(JSON_ERROR, JSON_ERROR_BAD_REGISTRATION); message.put(JSON_ERROR_DESCRIPTION, "Invalid token on 'to' field: " + jsonObject.get(JSON_TO)); String payload = JSONValue.toJSONString(message); StanzaBuilder builder = new StanzaBuilder("message"); builder.addAttribute("id", original.getAttributeValue("id") == null ? "" : original.getAttributeValue("id")); GCMMessage.Builder gcmMessageBuilder = new GCMMessage.Builder(); gcmMessageBuilder.addText(payload); builder.addPreparedElement(gcmMessageBuilder.build()); return builder.build(); }
From source file:de.minestar.minestarlibrary.utils.PlayerUtils.java
public static String getPlayerNameFromMojang(String uuid) { JSONArray array = getHTTPGetRequestAsArray("https://api.mojang.com/user/profiles/" + uuid + "/names"); JSONObject object = (JSONObject) array.get(array.size() - 1); return (String) object.get("name"); }
From source file:eu.dety.burp.joseph.utilities.Converter.java
/** * Get RSA PublicKey list by JWK JSON input with an identifying string * // ww w .j a va2 s.c om * @param input * JSON Web Key {@link JSONObject} * @return HashMap of {@link PublicKey} with identifying string as key */ public static HashMap<String, PublicKey> getRsaPublicKeysByJwkWithId(final Object input) { HashMap<String, PublicKey> keys = new HashMap<>(); if (!(input instanceof JSONObject)) return keys; JSONObject inputJsonObject = (JSONObject) input; // Multiple keys existent if (inputJsonObject.containsKey("keys")) { loggerInstance.log(Converter.class, "Key array found...", Logger.LogLevel.DEBUG); int counter = 1; for (final Object value : (JSONArray) inputJsonObject.get("keys")) { JSONObject keyJson = (JSONObject) value; PublicKey key = getRsaPublicKeyByJwk(keyJson); String id = "#" + counter; if (keyJson.containsKey("kty")) id += "_" + keyJson.get("kty"); if (keyJson.containsKey("alg")) id += "_" + keyJson.get("alg"); if (keyJson.containsKey("use")) id += "_" + keyJson.get("use"); if (keyJson.containsKey("kid")) id += "_" + keyJson.get("kid"); if (key != null) keys.put(id, key); counter++; } } else { PublicKey key = getRsaPublicKeyByJwk(inputJsonObject); if (key != null) keys.put("#1", key); } return keys; }
From source file:net.itransformers.toplogyviewer.gui.neo4j.Neo4jLoader.java
public static String getLatestNetwork() { String HighestNetworkID = null; String query = "start network=node:node_auto_index(name='network') return network"; String params = ""; String output = executeCypherQuery(query, params); JSONObject json = null; try {//w w w. j a v a 2 s . co m json = (JSONObject) new JSONParser().parse(output); } catch (ParseException e) { e.printStackTrace(); } JSONArray jsonData = (JSONArray) json.get("data"); JSONArray array = (JSONArray) jsonData.get(jsonData.size() - 1); JSONObject object1 = (JSONObject) array.get(array.size() - 1); String delims = "[/]"; //Get the latest element of the URL e.g the node ID. String[] tokens = object1.get("self").toString().split(delims); HighestNetworkID = tokens[tokens.length - 1]; return HighestNetworkID; }
From source file:it.polimi.logging.LogMessageUtils.java
public static boolean getValidBitFromMessage(String message) { JSONObject jsonMsg; JSONParser parser = new JSONParser(); String type = getEventType(message); if (type.equals(MessageType.CHECK_OUT.ordinal())) { try {// w w w.j a va2 s . com jsonMsg = (JSONObject) parser.parse(message); return (Boolean) jsonMsg.get(JsonStrings.VALID); } catch (ParseException e) { e.printStackTrace(); } } return false; }
From source file:com.nubits.nubot.options.ParseOptions.java
public static Object getIgnoreCase(JSONObject jobj, String key) { Iterator<String> iter = jobj.keySet().iterator(); while (iter.hasNext()) { String key1 = iter.next(); if (key1.equalsIgnoreCase(key)) { return jobj.get(key1); }/*from w ww . ja v a 2s . co m*/ } return null; }
From source file:freebase.api.FreebaseAPI2.java
public static List<Film> getFilms(String fromDate, String toDate) { try {/*from w ww. ja v a2 s . c o m*/ properties.load(new FileInputStream("freebase.properties")); HttpTransport httpTransport = new NetHttpTransport(); HttpRequestFactory requestFactory = httpTransport.createRequestFactory(); JSONParser parser = new JSONParser(); // String query = "[{\"id\":null,\"name\":null,\"type\":\"/astronomy/planet\"}]"; String query = readQueryFromFile("queries/q1.json"); query = manipulateQuery(query, fromDate, toDate); //JSONArray queryJObj = (JSONArray) JSONValue.parse(query); //query = queryJObj.toJSONString(); //query = "[{\"id\":null,\"name\":null,\"type\":\"/film/film\"}]"; //query = "[{\"mid\":null,\"name\":null,\"language\":\"English Language\",\"country\":\"United States of America\",\"type\":\"/film/film\",\"initial_release_date>=\":\"2000-01-01\",\"initial_release_date<=\":\"2020-01-01\",\"initial_release_date\":null,\"directed_by\":[{\"mid\":null,\"name\":null}],\"starring\":[{\"mid\":null,\"actor\":[{\"mid\":null,\"name\":null}],\"character\":[{\"mid\":null,\"name\":null}]}],\"limit\":1}]"; GenericUrl url = new GenericUrl("https://www.googleapis.com/freebase/v1/mqlread"); url.put("query", query); url.put("key", properties.get("API_KEY")); // url.put("cursor", current_cursor); System.out.println("URL:" + url); HttpRequest request = requestFactory.buildGetRequest(url); HttpResponse httpResponse = request.execute(); JSONObject response = (JSONObject) parser.parse(httpResponse.parseAsString()); JSONArray results = (JSONArray) response.get("result"); // if (response.get("cursor") instanceof Boolean) { // System.out.println("End of The Result, cursor=" + response.get("cursor")); // } else { // current_cursor = (String) response.get("cursor"); // } // System.out.println(results.toString()); Utils.writeDataIntoFile(results.toString() + "\n", JSON_DUMP_FILE); List<Film> films = encodeJSON(results); return films; // for (Object result : results) { // System.out.println(JsonPath.read(result, "$.name").toString()); // } } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:com.dynamobi.network.DynamoNetworkUdr.java
/** * Shows all available packages we have available. *//*w w w.j a va2 s.co m*/ public static void showPackages(PreparedStatement resultInserter) throws SQLException { List<RepoInfo> repos = getRepoUrls(); for (RepoInfo inf : repos) { String repo = inf.url; if (!inf.accessible) { resultInserter.setString(1, repo); resultInserter.setBoolean(2, inf.accessible); resultInserter.executeUpdate(); continue; } JSONObject repo_data = downloadMetadata(repo); JSONArray pkgs = (JSONArray) repo_data.get("packages"); for (JSONObject obj : (List<JSONObject>) pkgs) { String jar = jarName(obj); String status = getStatus(jar); int c = 0; resultInserter.setString(++c, repo); resultInserter.setBoolean(++c, inf.accessible); resultInserter.setString(++c, obj.get("type").toString()); resultInserter.setString(++c, obj.get("publisher").toString()); resultInserter.setString(++c, obj.get("package").toString()); resultInserter.setString(++c, obj.get("version").toString()); resultInserter.setString(++c, jar); resultInserter.setString(++c, status); resultInserter.setString(++c, obj.get("depend").toString()); resultInserter.setString(++c, obj.get("rdepend").toString()); resultInserter.executeUpdate(); } } }