List of usage examples for org.json.simple JSONArray get
public E get(int index)
From source file:ca.fastenalcompany.jsonconfig.ProductJson.java
@GET @Produces("application/json") public String doGet(@PathParam("id") Integer id) { query(PropertyManager.getProperty("db_selectAll")).toString(); JSONArray products = query(PropertyManager.getProperty("db_select"), id + ""); return products.isEmpty() ? new JSONObject().toString() : products.get(0).toString(); }
From source file:bigtweet.model.StudyingBeacons.java
/** * Extra ouput file to generate a chart * call plotBeaconStudy in R project to obtain chart *///from w w w . j av a2 s . c om private void generateBatchOuputForChart(JSONArray parametersValues, int parametersValuesIndex, double meanEndorsers) { JSONObject parameters = (JSONObject) parametersValues.get(parametersValuesIndex);//parameters JSONObject aux = new JSONObject(); aux.put("links", parameters.get("beaconLinksNumber")); aux.put("centrality", parameters.get("beaconLinksCentrality")); DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US); DecimalFormat df = new DecimalFormat("0.000", otherSymbols); aux.put("meanEndorsers", df.format(meanEndorsers)); JSONForChart.add(aux); //write json file FileWriter file; try { file = new FileWriter(batchOutputFileForChart); file.write(JSONForChart.toJSONString()); file.flush(); file.close(); } catch (Exception ex) { Logger.getLogger(BTSimBatch.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.github.itoshige.testrail.store.SectionStore.java
private void copyJsonArrayToMap(JSONArray from, ConcurrentHashMap<SectionStoreKey, String> to, String projectId, String runId, String key2, String value) { for (int i = 0; i < from.size(); i++) { JSONObject obj = (JSONObject) from.get(i); Object k2 = obj.get(key2); Object v = obj.get(value); if (projectId != null && k2 != null && v != null) { to.putIfAbsent(new SectionStoreKey(projectId, runId, k2.toString().trim()), v.toString().trim()); }//from w w w . j a v a 2s. c o m } }
From source file:com.ge.research.semtk.sparqlX.SparqlEndpointInterface.java
/** * Parse an auth query confirmation. The message will the first entry in the rows array. * @param rowsJsonArray//from w w w .j a v a2 s .c o m * @return */ private static String getAuthMessageFromResponse(JSONArray rowsJsonArray) { String message = ""; for (int i = 0; i < rowsJsonArray.size(); i++) { JSONObject row = (JSONObject) rowsJsonArray.get(i); // e.g. {"callret-0":{"type":"literal","value":"Insert into <http:\/\/research.ge.com\/dataset>, 1 (or less) triples -- done"}} JSONObject value; String key, valueValue; @SuppressWarnings("unchecked") Iterator<String> iter = row.keySet().iterator(); while (iter.hasNext()) { key = (String) iter.next(); value = (JSONObject) row.get(key); valueValue = (String) value.get("value"); message += valueValue; } } return message; }
From source file:com.noelportugal.amazonecho.AmazonEchoApi.java
public String getLatestHistory() throws IOException { String output = httpGet("/api/activities?startTime=&size=1&offset=-1"); //System.out.println(output); fLogger.log(Level.INFO, output); // Parse JSON Object obj = JSONValue.parse(output); JSONObject jsonObject = (JSONObject) obj; JSONArray values = (JSONArray) jsonObject.get("activities"); JSONObject item = (JSONObject) values.get(0); String text = item.get("description").toString(); fLogger.log(Level.INFO, text.toString()); //Get the summary text Object obj2 = JSONValue.parse(text); JSONObject jsonObject2 = (JSONObject) obj2; text = jsonObject2.get("summary").toString(); if (!checkItemId(text)) { return text; } else {//from w w w. j av a 2 s.c o m return null; } }
From source file:logica.ABB.java
public void llenar(JSONArray array) { ABB ar = new ABB(); for (int i = 0; i < array.size(); i++) { ar.insertar(array.get(i)); }//ww w . j a v a 2 s. c o m }
From source file:com.github.lgi2p.obirs.utils.IndexerJSON.java
public void indexItem(String json) throws IOException, ParseException { JSONParser parser = new JSONParser(); Object obj;//w w w .j av a 2 s . co m obj = parser.parse(json); JSONObject jsonObject = (JSONObject) obj; String uri = (String) jsonObject.get("uri").toString(); String label = (String) jsonObject.get("label"); String href = (String) jsonObject.get("href"); URI itemUri = URIFactoryMemory.getSingleton().getURI(uri); Set<URI> itemAnnotations = new HashSet(); ItemMetadata meta = new ItemMetadata(uri, label, href); JSONArray conceptIds = (JSONArray) jsonObject.get("annots"); for (int i = 0; i < conceptIds.size(); i++) { String conceptURI = (String) conceptIds.get(i); URI uriConcept = URIFactory.getURI(conceptURI); itemAnnotations.add(uriConcept); } items.add(new Item(itemUri, itemAnnotations)); metadata.put(itemUri, meta); }
From source file:com.mp.gw2api.base.GW2APIDataList.java
@Override public void LoadFromJsonText(String text) { JSONParser parser = new JSONParser(); JSONObject json;//from ww w .j ava 2 s . co m try { //Parse json array JSONArray ja = (JSONArray) parser.parse(text); //Create object array to retrieve data maps = new long[ja.size()]; if (ja != null) { for (int i = 0; i < ja.size(); i++) { maps[i] = (long) ja.get(i); } } } catch (ParseException ex) { Logger.getLogger(GW2APIDataList.class.getName()).log(Level.SEVERE, null, ex); maps = null; } }
From source file:fr.lirmm.yamplusplus.yampponline.TestOaeiAlignment.java
@Test public void testOaeiAlignment() throws IOException, ClassNotFoundException, OWLOntologyStorageException, SAXException { String iamlRameauAlignment = FileUtils .readFileToString(new File("src/test/resources/iaml-rameau_valid_test.rdf"), "UTF-8"); boolean testExtractValid = false; YamFileHandler fileHandler = new YamFileHandler(); JSONObject parseOaeiJson = new JSONObject(); parseOaeiJson = fileHandler.parseOaeiAlignmentFormat(iamlRameauAlignment); JSONArray entities = (JSONArray) parseOaeiJson.get("entities"); // Look for a specific valid mapping to test if parsing worked for (int i = 0; i < entities.size(); i++) { JSONObject mappingJObject = (JSONObject) entities.get(i); if (mappingJObject.get("valid").equals("valid") && mappingJObject.get("entity1").equals("http://iflastandards.info/ns/unimarc/terms/mop/wdb") && mappingJObject.get("entity2").equals("http://data.bnf.fr/ark:/12148/cb12270245r")) { testExtractValid = true;/*from w w w. j a v a2 s. c o m*/ break; } } //System.out.println(parseOaeiJson.toString()); assertTrue(testExtractValid); }
From source file:HostController.java
@RequestMapping("/hosts") public @ResponseBody Host host( @RequestParam(value = "authentication", required = false, defaultValue = "") String authentication) throws FileNotFoundException, UnsupportedEncodingException, IOException { Properties props = new Properties(); FileInputStream fis = new FileInputStream("properties.xml"); //loading properites from properties file props.loadFromXML(fis);//from w w w . j a va2 s . co m String server_ip = props.getProperty("server_ip"); String ZABBIX_API_URL = "http://" + server_ip + "/api_jsonrpc.php"; // 1.2.3.4 is your zabbix_server_ip HttpClient client = new HttpClient(); PutMethod putMethod = new PutMethod(ZABBIX_API_URL); // content-type is controlled in api_jsonrpc.php, so set it like this putMethod.setRequestHeader("Content-Type", "application/json-rpc"); // create json object for apiinfo.version JSONParser parser = new JSONParser(); JSONObject jsonObj = new JSONObject(); JSONArray list = new JSONArray(); jsonObj.put("jsonrpc", "2.0"); jsonObj.put("method", "host.get"); JSONObject params = new JSONObject(); params.put("output", "extend"); jsonObj.put("params", params); jsonObj.put("auth", authentication);// todo jsonObj.put("id", new Integer(1)); putMethod.setRequestBody(jsonObj.toString()); // put the json object as input stream into request body String loginResponse = ""; try { client.executeMethod(putMethod); // send to request to the zabbix api loginResponse = putMethod.getResponseBodyAsString(); // read the result of the response Object obj = parser.parse(loginResponse); JSONObject obj2 = (JSONObject) obj; String jsonrpc = (String) obj2.get("jsonrpc"); JSONArray array = (JSONArray) obj2.get("result"); for (int i = 0; i < array.size(); i++) { JSONObject tobj = (JSONObject) array.get(i); JSONObject objret = new JSONObject(); objret.put("hostid", tobj.get("hostid")); objret.put("hostName", tobj.get("host")); list.add(objret); } return new Host(list); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException pe) { pe.printStackTrace(); } return new Host( "Error: please provide the appropriate input parameters of the metric you are looking for its corresponding monitoring data:"); }