List of usage examples for org.json.simple JSONObject get
V get(Object key);
From source file:de.hstsoft.sdeep.model.TerrainGeneration.java
public static TerrainGeneration parse(JSONObject json) { TerrainGeneration terrainGeneration = new TerrainGeneration(); JSONObject origin = (JSONObject) json.get(WORLD_ORIGIN_POINT); terrainGeneration.worldOrigin = Position.parseVector(origin); JSONObject playerPosition = (JSONObject) json.get(PLAYER_POSITION); terrainGeneration.playerPosition = Position.parseVector(playerPosition); terrainGeneration.worldSeed = Utils.toInt(json.get(WORLD_SEED).toString()); JSONObject nodes = (JSONObject) json.get(NODES); Iterator<?> iter = nodes.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<?, ?> entry = (Map.Entry<?, ?>) iter.next(); String key = entry.getKey().toString(); JSONObject node = (JSONObject) nodes.get(entry.getKey().toString()); TerrainNode terrainNode = TerrainNode.parseNode(key, node); terrainGeneration.terrainNodes.add(terrainNode); }/*from w w w . ja va 2 s. c o m*/ return terrainGeneration; }
From source file:Bing.java
/** * * @param query - query to use for the search * @return - a json array of results. each contains a title, description, url, * and some other metadata that can be easily extracted since its in json format *//*from ww w . j a v a 2s . co m*/ public static JSONArray search(String query) { try { query = "'" + query + "'"; String encodedQuery = URLEncoder.encode(query, "UTF-8"); System.out.println(encodedQuery); // URL url = new URL("https://api.datamarket.azure.com/Bing/Search/v1/Composite?Sources=%27web%27&Query=%27car%27"); // URL url = new URL("http://csb.stanford.edu/class/public/pages/sykes_webdesign/05_simple.html"); String webPage = "https://api.datamarket.azure.com/Bing/Search/v1/Composite?Sources=%27web%27&Query=" + encodedQuery + "&$format=JSON"; String name = "6604d12c-3e89-4859-8013-3132f78c1595"; String password = "cefgNRl3OL4PrJJvssxkqLw0VKfYNCgyTe8wNXotUmQ"; String authString = name + ":" + password; System.out.println("auth string: " + authString); byte[] authEncBytes = Base64.encodeBase64(authString.getBytes()); String authStringEnc = new String(authEncBytes); System.out.println("Base64 encoded auth string: " + authStringEnc); URL url = new URL(webPage); URLConnection urlConnection = url.openConnection(); urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc); BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); String inputLine; StringBuilder response = new StringBuilder(); while ((inputLine = in.readLine()) != null) { response.append(inputLine).append("\n"); } in.close(); JSONParser parser = new JSONParser(); JSONArray arr = (JSONArray) ((JSONObject) ((JSONObject) parser.parse(response.toString())).get("d")) .get("results"); JSONObject obj = (JSONObject) arr.get(0); JSONArray out = (JSONArray) obj.get("Web"); return out; // } catch (MalformedURLException ex) { Logger.getLogger(Bing.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Bing.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException ex) { Logger.getLogger(Bing.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:com.mobicage.rogerthat.SearchConfig.java
public static SearchConfig fromJSONObject(JSONObject jsonObject) { SearchConfig searchConfig = new SearchConfig(); searchConfig.enabled = (Boolean) jsonObject.get("enabled"); searchConfig.keywords = (String) jsonObject.get("keywords"); searchConfig.locations = new ArrayList<SearchLocation>(); for (Object locationObject : (JSONArray) jsonObject.get("locations")) { searchConfig.locations.add(SearchLocation.fromJSONObject((JSONObject) locationObject)); }//ww w. j a v a 2 s . c o m return searchConfig; }
From source file:com.github.itoshige.testrail.client.TestRailClient.java
/** * return projectId and suiteId/* w w w . j a v a 2 s . co m*/ * * @param runId * @return projectId & suiteId */ public static RunStoreValue getRun(String runId) { JSONObject obj = (JSONObject) get(String.format("get_run/%s", runId)); Object projectId = obj.get("project_id"); Object suiteId = obj.get("suite_id"); if (projectId != null && suiteId != null) return new RunStoreValue(projectId.toString(), suiteId.toString()); throw new TestInitializerException(String.format("test run data isn't in testrail. runId:%s", runId)); }
From source file:com.serena.rlc.provider.jenkins.domain.Job.java
public static Job parseSingle(JSONObject jsonObject) { Job obj = new Job(); if (jsonObject != null) { obj.setName((String) jsonObject.get("name")); obj.setDisplayName((String) jsonObject.get("displayName")); }/*from www.ja v a2 s .co m*/ return obj; }
From source file:com.wso2.raspberrypi.apicalls.APICall.java
public static List<Zone> listZones() { List<Zone> zones = new ArrayList<Zone>(); Token token = getToken();/*w w w. jav a2 s . co m*/ if (token != null) { HttpClient httpClient = new HttpClient(); try { HttpResponse httpResponse = httpClient.doGet(apiURLPrefix + "/conferences/2/iot/zones", "Bearer " + token.getAccessToken()); int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode == 200) { JSONParser parser = new JSONParser(); JSONArray jsonArray = (JSONArray) parser.parse(httpClient.getResponsePayload(httpResponse)); for (int i = 0; i < jsonArray.size(); i++) { JSONObject obj = (JSONObject) jsonArray.get(i); zones.add(new Zone((String) obj.get("id"), (String) obj.get("name"))); } } else { log.error("Could not get Zones. HTTP Status code: " + statusCode); } } catch (IOException e) { log.error("", e); } catch (ParseException e) { log.error("", e); } } return zones; }
From source file:de.tuttas.websockets.ChatServer.java
public static void send(JSONObject msg, Session myself) { Log.d("Sende " + msg.toJSONString()); msg.put("msg", StringUtil.escapeHtml((String) msg.get("msg"))); for (Session s : sessions) { if (s != myself) { try { s.getBasicRemote().sendText(msg.toJSONString()); } catch (IOException ex) { Logger.getLogger(ChatServer.class.getName()).log(Level.SEVERE, null, ex); ex.printStackTrace();//w w w . ja v a 2 s. c o m } } } }
From source file:eu.ebbitsproject.peoplemanager.utils.HttpUtils.java
public static String findPerson(String errorType, String location) { CloseableHttpClient httpClient = HttpClients.createDefault(); String url = PropertiesUtils.getProperty("uiapp.address"); HttpPost httpPost = new HttpPost(url); List<NameValuePair> nvps = new ArrayList<>(); nvps.add(new BasicNameValuePair("action", "find-persons")); String properties = "demo-e1:competence=" + errorType + ",demo-e1:area-responsibility=" + location; String pmProperties = "available=true"; nvps.add(new BasicNameValuePair("properties", properties)); nvps.add(new BasicNameValuePair("pmProperties", pmProperties)); try {/* ww w . j a v a 2 s . c om*/ httpPost.setEntity(new UrlEncodedFormEntity(nvps)); } catch (UnsupportedEncodingException ex) { Logger.getLogger(HttpUtils.class.getName()).log(Level.SEVERE, null, ex); } CloseableHttpResponse response = null; String personJSON = null; try { response = httpClient.execute(httpPost); personJSON = EntityUtils.toString(response.getEntity()); System.out.println("######## PersonJSON: " + personJSON); } catch (IOException e) { Logger.getLogger(HttpUtils.class.getName()).log(Level.SEVERE, null, e); } finally { try { response.close(); } catch (IOException e) { Logger.getLogger(HttpUtils.class.getName()).log(Level.SEVERE, null, e); } } if (personJSON != null) { JSONArray persons = (JSONArray) JSONValue.parse(personJSON); Iterator<JSONObject> i = persons.iterator(); if (i.hasNext()) { JSONObject o = i.next(); return o.get("id").toString(); } } return personJSON; }
From source file:com.avatarproject.core.storage.UserCache.java
/** * Gets a UUID of a user from the custom UserCache. * @param playername String name of the player to get. * @return UUID of the player./*w w w . ja va 2s . c o m*/ */ public static UUID getUser(String playername) { JSONArray array = getUserCache(); try { for (int n = 0; n < array.size(); n++) { //Loop through all the objects in the array. JSONObject object = (JSONObject) array.get(n); if (String.valueOf(object.get("name")).equalsIgnoreCase(playername)) { return UUID.fromString(String.valueOf(object.get("id"))); } } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:edu.sjsu.cohort6.esp.common.CommonUtils.java
/** * This method parses the generic jersey response to a generic JSONObject and singles out the "entity" piece * from the generic response.//from w ww . j a v a 2 s.co m * * @param response * @return * @throws org.json.simple.parser.ParseException */ private static String getJsonFromResponse(Response response) throws org.json.simple.parser.ParseException { String c = response.readEntity(String.class); log.info(c.toString()); JSONParser parser = new JSONParser(); JSONObject json = (JSONObject) parser.parse(c); JSONObject jsonObject = (JSONObject) json.get("entity"); return jsonObject.toJSONString(); }