List of usage examples for org.json.simple JSONArray get
public E get(int index)
From source file:cqels_shim.StdinStream.java
/** * start listening to stdin and forwarding to cqels *//*from w w w . j a v a 2 s . c om*/ public void run() { try { JSONParser parser = new JSONParser(); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String line; while ((line = reader.readLine()) != null && !stop) { try { Object obj = parser.parse(line); JSONArray array = (JSONArray) obj; //stream the triple stream(n((String) array.get(0)), n((String) array.get(1)), n((String) array.get(2))); } catch (ParseException pe) { System.err.println("Error when parsing input, incorrect JSON."); } if (sleep > 0) { try { Thread.sleep(sleep); } catch (InterruptedException e) { e.printStackTrace(); } } } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.rackspacecloud.blueflood.outputs.serializers.JSONHistogramOutputSerializerTest.java
@Test public void testHistogramRollupsSerialization() throws SerializationException { final JSONHistogramOutputSerializer serializer = new JSONHistogramOutputSerializer(); final MetricData metricData = new MetricData(FakeMetricDataGenerator.generateFakeHistogramRollupPoints(), "unknown", MetricData.Type.HISTOGRAM); JSONObject metricDataJSON = serializer.transformHistogram(metricData); final JSONArray data = (JSONArray) metricDataJSON.get("values"); for (int i = 0; i < data.size(); i++) { final JSONObject dataJSON = (JSONObject) data.get(i); final Points.Point point = (Points.Point) metricData.getData().getPoints() .get(dataJSON.get("timestamp")); JSONArray hist = (JSONArray) dataJSON.get("histogram"); Assert.assertNotNull(hist);/* w w w. ja va2 s . c o m*/ for (int j = 0; j < hist.size(); j++) { JSONObject bin = (JSONObject) hist.get(j); Assert.assertNotNull(bin.get("count")); Assert.assertNotNull(bin.get("mean")); } } }
From source file:Bean.ObjectStorageConnector.java
public void getConnection() { try {/* w w w. java2 s .co m*/ String envApp = System.getenv("VCAP_APPLICATION"); String envServices = System.getenv("VCAP_SERVICES"); JSONParser parser = new JSONParser(); Object obj = parser.parse(envServices); JSONObject jsonObject = (JSONObject) obj; JSONArray vcapArray = (JSONArray) jsonObject.get("Object-Storage"); JSONObject vcap = (JSONObject) vcapArray.get(0); JSONObject credentials = (JSONObject) vcap.get("credentials"); auth_url = credentials.get("auth_url").toString() + "/v3"; project = credentials.get("project").toString(); projectId = credentials.get("projectId").toString(); region = credentials.get("region").toString(); userId = credentials.get("userId").toString(); username = credentials.get("username").toString(); password = credentials.get("password").toString(); domainId = credentials.get("domainId").toString(); domainName = credentials.get("domainName").toString(); Identifier domainIdent = Identifier.byName(domainName); Identifier projectIdent = Identifier.byName(project); os = OSFactory.builderV3().endpoint(auth_url).credentials(userId, password) .scopeToProject(projectIdent, domainIdent).authenticate(); account = os.objectStorage().account().get(); } catch (ParseException ex) { } }
From source file:guestbook.Entity.java
protected Object retrieveValue(String p, String type) { Set s = statements.keySet();/*ww w. j a va 2 s. com*/ if (s.contains(p)) { JSONArray statement = (JSONArray) statements.get(p); JSONObject x = (JSONObject) statement.get(0); JSONObject mainsnak = (JSONObject) x.get("mainsnak"); JSONObject datavalue = (JSONObject) mainsnak.get("datavalue"); JSONObject value = (JSONObject) datavalue.get("value"); Object object = value.get(type); return object; } return null; }
From source file:com.github.itoshige.testrail.store.TestStore.java
private void copyJsonArrayToMap(JSONArray from, ConcurrentHashMap<String, String> to, String key, String value) {/* w ww . jav a 2 s .c om*/ for (int i = 0; i < from.size(); i++) { JSONObject obj = (JSONObject) from.get(i); copyJsonObjToMap(obj, to, key, value); } }
From source file:com.bradleyjh.blazefly.Updater.java
public void run() { URL url;//from ww w. j a v a2 s . c o m try { url = new URL("https://api.curseforge.com/servermods/files?projectIds=50224"); } catch (MalformedURLException e) { return; } try { URLConnection conn = url.openConnection(); final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); String response = reader.readLine(); JSONArray array = (JSONArray) JSONValue.parse(response); if (array.size() > 0) { JSONObject latest = (JSONObject) array.get(array.size() - 1); String latestFile = (String) latest.get("name"); // SomePlugin v2.3 = "230", SomePlugin v2.3.4 = "234" // means we can check if the newer file is a newer version String latestVersion = latestFile.replaceAll("\\D+", ""); if (latestVersion.length() == 2) { latestVersion = latestVersion + "0"; } thisVersion = thisVersion.replaceAll("\\D+", ""); if (thisVersion.length() == 2) { thisVersion = thisVersion + "0"; } if (Integer.parseInt(latestVersion) > Integer.parseInt(thisVersion)) { main.updateAvailable = latestFile; main.getLogger().info(latestFile + " is available for download!"); } } } catch (IOException e) { return; } }
From source file:org.uom.fit.level2.datavis.controllers.chatController.ChatController.java
@RequestMapping(value = "/allmessage", method = RequestMethod.GET) public JSONArray AllMessage() { JSONArray message = new JSONArray(); JSONArray messagelength = chatServices.getAllChatDataAllMessage(); for (int i = 0; i < messagelength.toArray().length; i++) { message.add(chatServices.getAllChatData(messagelength.get(i).toString())); }// w w w .j a v a 2s .co m return message; }
From source file:com.thesmartweb.swebrank.BingResults.java
/** * Class to get the results number from Bing in order to use it in NWD * @param quer the query to get the results for * @param config_path the path with the configuration file (api keys for bing) * @return the number of the results for a certain query *///from w w w .j a va2 s .c o m public Long Get_Results_Number(String quer, String config_path) { try { long results_number = 0; //we check if we have an extra useless + in the end String check_quer = quer.substring(quer.length() - 1, quer.length()); char plus = "+".charAt(0); char check_plus = check_quer.charAt(0); if (check_plus == plus) { quer = quer.substring(0, quer.length() - 1); } quer = quer.replace("+", "%20"); //we connect through the Bing search api URL azure_url = new URL( "https://api.datamarket.azure.com/Bing/Search/Composite?Sources=%27web%27&Query=%27" + quer + "%27&$format=JSON"); APIconn apicon = new APIconn(); String line = apicon.azureconnect(azure_url, config_path); if ((!line.equalsIgnoreCase("fail")) && (!line.equalsIgnoreCase("insufficient")) && (!line.equalsIgnoreCase("provided"))) { //Create a parser of the json JSONParser parser = new JSONParser(); //Create the map Map json = (Map) parser.parse(line); // Get a set of the entries Set set = json.entrySet(); Object[] arr = set.toArray(); Map.Entry entry = (Map.Entry) arr[0]; //get to second level of yahoo json String you = entry.getValue().toString(); json = (Map) parser.parse(you); set = json.entrySet(); arr = set.toArray(); entry = (Map.Entry) arr[0]; you = entry.getValue().toString(); Object parse = parser.parse(you); JSONArray json_new = (JSONArray) parse; json = (Map) json_new.get(0); set = json.entrySet(); arr = set.toArray(); Map.Entry[] entries_bing = null; int k = 0; Iterator new_iterator = set.iterator(); while (new_iterator.hasNext()) { Object next = new_iterator.next(); Map.Entry next_entry = (Map.Entry) next; if (next_entry.getKey().toString().equalsIgnoreCase("WebTotal")) { results_number = Long.parseLong(next_entry.getValue().toString()); } } } return results_number; } catch (MalformedURLException | ParseException | java.lang.ArrayIndexOutOfBoundsException | java.lang.NullPointerException | NumberFormatException ex) { Logger.getLogger(BingResults.class.getName()).log(Level.SEVERE, null, ex); long results_number = 0; return results_number; } }
From source file:cqels_shim.SocketStream.java
/** * start listening on the socket and forwarding to cqels *///from w ww . j av a 2 s . com public void run() { ServerSocket ssock = null; Socket sock = null; try { ssock = new ServerSocket(this.port); sock = ssock.accept(); DataInputStream is = new DataInputStream(sock.getInputStream()); JSONParser parser = new JSONParser(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line; while ((line = reader.readLine()) != null && !stop) { try { Object obj = parser.parse(line); JSONArray array = (JSONArray) obj; //stream the triple stream(n((String) array.get(0)), n((String) array.get(1)), n((String) array.get(2))); } catch (ParseException pe) { System.err.println("Error when parsing input, incorrect JSON."); } if (sleep > 0) { try { Thread.sleep(sleep); } catch (InterruptedException e) { e.printStackTrace(); } } } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.blogspot.jadecalyx.webtools.jcAddressIndex.java
private void loadIndexFromJson(String site) throws Exception { String s = System.getProperty("file.separator"); String runPath = System.getProperty("user.dir"); String fullPath = String.join(s, runPath, "SiteInfo", site, "AddressInfo", "addresses.json"); File f = new File(fullPath); if (!f.isFile()) { throw new Exception(String.format("loadIndex unable to find file for site: %s", site)); }// w ww . j a va 2 s . c o m //load json file JSONParser parser = new JSONParser(); Object obj = parser.parse(new FileReader(fullPath)); JSONObject jsonObject = (JSONObject) obj; JSONArray addressList = (JSONArray) jsonObject.get("address-list"); for (int i = 0; i < addressList.size(); i++) { JSONObject address = (JSONObject) addressList.get(i); _addresses.put(address.get("handle").toString(), new jcAddressSet(address.get("segment").toString(), address.get("mask").toString())); } }