List of usage examples for org.json.simple JSONArray get
public E get(int index)
From source file:csparql_shim.StdinStream.java
/** * start listening to stdin and forwarding to csparql * stream in defined windows to allow comparison with cqels *///from ww w .j av a 2 s . com @Override public void run() { try { JSONParser parser = new JSONParser(); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String line; int windowcount = 1; //loop for streaming in data while ((line = reader.readLine()) != null && !stop) { try { Object obj = parser.parse(line); JSONArray array = (JSONArray) obj; //stream the triple final RdfQuadruple q = new RdfQuadruple((String) array.get(0), (String) array.get(1), (String) array.get(2), System.currentTimeMillis()); this.put(q); System.out.println("triple sent at: " + System.currentTimeMillis()); } catch (ParseException pe) { System.err.println("Error when parsing input, incorrect JSON."); } } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.greymemory.nab.Labels.java
public void Read(String file_name) { JSONParser parser = new JSONParser(); try {//from w w w .j a v a 2s . c o m JSONObject root = (JSONObject) parser.parse(new FileReader(file_name)); SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); files.clear(); for (Object key : root.keySet()) { NAB_File f = new NAB_File(); f.file_name = (String) key; JSONArray file = (JSONArray) root.get(key); Iterator<JSONArray> iterator_file = file.iterator(); while (iterator_file.hasNext()) { JSONArray timestamps = iterator_file.next(); NAB_Anomaly a = new NAB_Anomaly(); a.start = format1.parse((String) timestamps.get(0)); a.stop = format1.parse((String) timestamps.get(1)); f.anomalies.add(a); } files.add(f); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } catch (java.text.ParseException e) { e.printStackTrace(); } }
From source file:logica.Array.java
public JSONArray crearJson(int tipo) { JSONArray Json = new JSONArray(); if (tipo == 0) Json.addAll(array);/*from w w w. j a va 2s.c o m*/ else Json.addAll(arrayPC); System.out.println(Json); System.out.println(Json.get(1)); return Json; }
From source file:com.appzone.sim.services.handlers.MtLogCheckServiceHandlerTest.java
public void testServeNormal() { final HttpServletRequest request = context.mock(HttpServletRequest.class); MtMessageRepository repository = new MemoryMtMessageRepository(); ServiceHandler handler = new MtLogCheckServiceHandler(repository); // setting some dummy messages repository.add(new MtMessage("message", null, 10)); repository.add(new MtMessage("message", null, 100)); repository.add(new MtMessage("message", null, 101)); repository.add(new MtMessage("message", null, 1001)); repository.add(//w w w . j ava 2 s . co m new MtMessage("message", Arrays.asList(new String[] { "tel:823728", "list:all_registered" }), 999)); context.checking(new Expectations() { { allowing(request).getParameter(DefaultKewordMatcher.SERVICE_KEYWORD); will(returnValue(MtLogCheckServiceHandler.MATCHING_KEYWORD)); allowing(request).getParameter(MtLogCheckServiceHandler.KEY_SINCE); will(returnValue("900")); } }); String jsonStr = handler.serve(request); JSONArray result = (JSONArray) JSONValue.parse(jsonStr); assertEquals(2, result.size()); JSONArray addresses = (JSONArray) ((JSONObject) result.get(1)) .get(MtLogCheckServiceHandler.JSON_KEY_ADDRESSES); assertEquals(2, addresses.size()); }
From source file:com.neu.bigdata.service.PredictionService.java
public double getSuccessPrediction() { double successRate = 0; String response = rrsHttpPost(); JSONParser parser = new JSONParser(); try {//from w ww . ja v a 2 s .c om Object responseJSON = parser.parse(response); JSONObject root = (JSONObject) responseJSON; JSONObject results = getJSONObject("Results", root); JSONObject output1 = getJSONObject("output1", results); JSONObject value = getJSONObject("value", output1); JSONArray values = getJSONArray("Values", value); JSONArray firstValues = getJSONArray(0, values); Object finalValue = firstValues.get(35); successRate = Double.parseDouble(finalValue.toString()); successRate = (successRate / 7.5) * 100.000; } catch (Exception ex) { ex.printStackTrace(); } return successRate; }
From source file:com.neu.bigdata.service.PredictionService.java
private JSONArray getJSONArray(int index, JSONArray root) { JSONArray array = null;/*from ww w. j a va 2 s . com*/ try { Object json = root.get(index); array = (JSONArray) json; } catch (Exception e) { e.printStackTrace(); } finally { return array; } }
From source file:de.uni_koblenz.aggrimm.icp.interfaceAgents.bing.BingResultParser.java
/** * @param o a parsed Bing bingResult string parsed to a JSONObject. * @param source from where the results are ("web" or "image"). * @param skip integer of manually skipped values - needed * for {@code isEmpty()}. * * @return {@code BingResultsContainer} with all extracted BingResults and * set {@code resultsTotal} and {@code offset}. * * @throws IllegalArgumentException when {@code source>} is unknown. *//*from w ww . ja v a 2 s .c om*/ @Override public BingResultsContainer<IUnfilteredResult> convertToResultContainer(JSONObject o, String source, int skip) { source = Character.toUpperCase(source.charAt(0)) + source.substring(1); o = (JSONObject) o.get("d"); JSONArray unwrappedJSONArray = (JSONArray) o.get("results"); o = (JSONObject) unwrappedJSONArray.get(0); JSONArray a = (JSONArray) o.get(source); BingResultsContainer<IUnfilteredResult> l = new BingResultsContainer<>(); areInformationFlowsAllowed = databaseQueryHelper.doesDefaultRuleAllowInformationFlows(); switch (source) { case "Web": { for (Object resultObject : a) { JSONObject result = (JSONObject) resultObject; l.add(extractBingWebResult(result)); } break; } case "Image": { for (Object resultObject : a) { JSONObject result = (JSONObject) resultObject; l.add(extractBingImageResult(result)); } break; } default: throw new IllegalArgumentException("source parameter was unknown: " + source); } l.setResultsTotal(getIntValue(o, source + "Total")); l.setOffset(getIntValue(o, source + "Offset")); l.setSkip(skip); return l; }
From source file:csparql_shim.SocketStream.java
/** * start listening on a socket and forwarding to csparql * stream in defined windows to allow comparison with cqels */// w w w .ja v a 2s . com @Override 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; int windowcount = 1; //loop for streaming in data while ((line = reader.readLine()) != null && !stop) { try { Object obj = parser.parse(line); JSONArray array = (JSONArray) obj; //stream the triple final RdfQuadruple q = new RdfQuadruple((String) array.get(0), (String) array.get(1), (String) array.get(2), System.currentTimeMillis()); this.put(q); System.out.println("triple sent at: " + System.currentTimeMillis()); } catch (ParseException pe) { System.err.println("Error when parsing input, incorrect JSON."); } } } catch (IOException e) { e.printStackTrace(); } }
From source file:ch.asadzia.cognitive.EmotionDetect.java
public ServiceResult process() { HttpClient httpclient = HttpClients.createDefault(); try {//from ww w .j av a 2 s .c om URIBuilder builder = new URIBuilder("https://api.projectoxford.ai/emotion/v1.0/recognize"); URI uri = builder.build(); HttpPost request = new HttpPost(uri); request.setHeader("Content-Type", "application/octet-stream"); request.setHeader("Ocp-Apim-Subscription-Key", apikey); // Request body FileEntity reqEntity = new FileEntity(imageData); request.setEntity(reqEntity); HttpResponse response = httpclient.execute(request); HttpEntity entity = response.getEntity(); if (entity != null) { String responseStr = EntityUtils.toString(entity); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { System.err.println(responseStr); return null; } JSONArray jsonArray = (JSONArray) new JSONParser().parse(responseStr); JSONObject jsonObject = (JSONObject) jsonArray.get(0); HashMap<char[], Double> scores = (HashMap) jsonObject.get("scores"); Map.Entry<char[], Double> maxEntry = null; for (Map.Entry<char[], Double> entry : scores.entrySet()) { System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue()); if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0) { maxEntry = entry; } } Object key = maxEntry.getKey(); String winningEmotionName = (String) key; ServiceResult result = new ServiceResult(translateEmotion(winningEmotionName), winningEmotionName); System.out.println(responseStr); return result; } } catch (Exception e) { System.err.println(e.toString()); } return null; }
From source file:com.endgame.binarypig.util.JsonUtil.java
public Object wrap(Object value) { if (isNestedLoadEnabled && value instanceof JSONObject) { return walkJson((JSONObject) value); } else if (isNestedLoadEnabled && value instanceof JSONArray) { JSONArray a = (JSONArray) value; DataBag mapValue = new NonSpillableDataBag(a.size()); for (int i = 0; i < a.size(); i++) { Tuple t = tupleFactory.newTuple(wrap(a.get(i))); mapValue.add(t);/*from ww w . j a v a 2 s .com*/ } return mapValue; } else { return value != null ? value.toString() : null; } }