List of usage examples for org.json.simple JSONArray get
public E get(int index)
From source file:com.example.austin.test.TextActivity.java
private void PrintOCRResponse(String jsonResponse) throws ParseException, IOException { JSONParser parser = new JSONParser(); JSONObject jsonObj = (JSONObject) parser.parse(jsonResponse); JSONArray text = (JSONArray) jsonObj.get("OCRText"); String result = ""; for (int i = 0; i < text.size(); i++) { result = result + " " + text.get(i); }/*from w w w. j a va 2 s. c o m*/ final TextView textView = (TextView) findViewById(R.id.textView); textView.setText(result); }
From source file:com.att.voice.AmazonEchoApi.java
public String getLatestTodo() throws IOException { String output = httpGet("/api/todos?type=TASK&size=1"); // Parse JSON Object obj = JSONValue.parse(output); JSONObject jsonObject = (JSONObject) obj; JSONArray values = (JSONArray) jsonObject.get("values"); JSONObject item = (JSONObject) values.get(0); // Get text and itemId String text = item.get("text").toString(); String itemId = item.get("itemId").toString(); if (!checkItemId(itemId)) { addItemId(itemId);//from ww w .jav a 2 s. com return text; } else { return null; } }
From source file:logic.ZybezQuery.java
public ArrayList<String> getItemIDList() { ArrayList<String> itemIDs = new ArrayList(); try {// w ww .ja va2 s . c o m String s = getJsonString(); JSONArray array = (JSONArray) JSONValue.parse(s); int numItems = array.size(); for (int i = 0; i < numItems; i++) { JSONObject o = ((JSONObject) array.get(i)); itemIDs.add(o.get("id").toString()); } } catch (IOException ex) { Logger.getLogger(ZybezQuery.class.getName()).log(Level.SEVERE, null, ex); } return itemIDs; }
From source file:edu.anu.spice.SpiceRefTupleTest.java
protected void compare(JSONArray expected, JSONArray actual) { assertEquals("Output wrong number of results", expected.size(), actual.size()); for (int i = 0; i < expectedOutput.size(); i++) { JSONObject expectedItem = (JSONObject) expected.get(i); JSONObject actualItem = (JSONObject) actual.get(i); // Image id assertEquals("Incorrect image id", expectedItem.get("image_id"), actualItem.get("image_id")); // Ref tuples JSONArray expectedRefTuples = (JSONArray) expectedItem.get("ref_tuples"); JSONArray actualRefTuples = (JSONArray) actualItem.get("ref_tuples"); compareTuples(expectedRefTuples, actualRefTuples, "ref", expectedItem.get("image_id")); }//from w ww. ja v a 2s . c o m }
From source file:edu.anu.spice.SpiceTestTupleTest.java
protected void compare(JSONArray expected, JSONArray actual) { assertEquals("Output wrong number of results", expected.size(), actual.size()); for (int i = 0; i < expectedOutput.size(); i++) { JSONObject expectedItem = (JSONObject) expected.get(i); JSONObject actualItem = (JSONObject) actual.get(i); // Image id assertEquals("Incorrect image id", expectedItem.get("image_id"), actualItem.get("image_id")); // Test tuples JSONArray expectedTestTuples = (JSONArray) expectedItem.get("test_tuples"); JSONArray actualTestTuples = (JSONArray) actualItem.get("test_tuples"); compareTuples(expectedTestTuples, actualTestTuples, "test", expectedItem.get("image_id")); }// ww w .j a v a 2 s .c om }
From source file:com.github.itoshige.testrail.store.CaseStore.java
private void copyJsonArrayToMap(JSONArray from, ConcurrentHashMap<CaseStoreKey, String> to, String key1, String key2, String value) { for (int i = 0; i < from.size(); i++) { JSONObject obj = (JSONObject) from.get(i); Object k1 = obj.get(key1); Object k2 = obj.get(key2); Object v = obj.get(value); if (k1 != null && k2 != null && v != null) { to.putIfAbsent(new CaseStoreKey(k1.toString().trim(), k2.toString().trim()), v.toString().trim()); }//from w ww . j ava2 s .co m } }
From source file:jcine.AsientosClient.java
public Asiento[] getAsientos() throws IOException, ParseException { HttpURLConnection conn = (HttpURLConnection) entryPoint.openConnection(); conn.setRequestMethod("GET"); conn.setDoOutput(true);//from w w w. ja va 2s . c o m StringBuilder builder = new StringBuilder(); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); String line; while ((line = reader.readLine()) != null) { builder.append(line); } JSONParser parser = new JSONParser(); JSONArray list = (JSONArray) parser.parse(builder.toString()); Asiento[] result = new Asiento[list.size()]; for (int i = 0; i < list.size(); i++) { JSONObject obj = (JSONObject) list.get(i); String name = (String) obj.get("numero"); Long posX = (Long) obj.get("posicionX"); Long posY = (Long) obj.get("posicionY"); result[i] = new Asiento(name, posX.intValue(), posY.intValue()); } return result; }
From source file:StudentsUpdate.java
private void getStud(String result) { System.out.println("result ==>" + result); try {// w w w . j a v a 2s. c om JSONParser parser = new JSONParser(); JSONObject mainjsonObj = (JSONObject) parser.parse(result); JSONArray jsonar = (JSONArray) mainjsonObj.get("students"); for (int i = 0; i < jsonar.size(); i++) { JSONObject c = (JSONObject) jsonar.get(i); // System.out.println(c.get("pa")); // stud.add("sk"); // pa.add((String)c.get("pa")); } } catch (Exception e) { e.printStackTrace(); } }
From source file:model.SearchResponse.java
@Override public void load(JSONObject object) { Iterator it = object.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, Object> pair = (Map.Entry) it.next(); String key = pair.getKey(); Object value = pair.getValue(); if (value == null) { continue; }/*from w ww . ja v a 2 s .co m*/ switch (key) { case "used_indices": this.used_indices = new Index(); JSONArray usedIndices = (JSONArray) value; if (usedIndices.size() == 1) { this.used_indices.load((JSONObject) usedIndices.get(0)); } break; case "messages": this.loadMessage((JSONArray) value); break; default: this.setAttribute(key, value.toString()); } } System.out.println(this); }
From source file:edu.anu.spice.SpiceScoreTest.java
@SuppressWarnings("unchecked") protected void compare(JSONArray expected, JSONArray actual) { assertEquals("Output wrong number of results", expected.size(), actual.size()); for (int i = 0; i < expectedOutput.size(); i++) { JSONObject expectedItem = (JSONObject) expected.get(i); JSONObject actualItem = (JSONObject) actual.get(i); // Image id assertEquals("Incorrect image id", expectedItem.get("image_id"), actualItem.get("image_id")); // Scores JSONObject testScores = (JSONObject) actualItem.get("scores"); JSONObject refScores = (JSONObject) expectedItem.get("scores"); Set<Map.Entry<String, JSONObject>> entrySet = refScores.entrySet(); for (Map.Entry<String, JSONObject> e : entrySet) { assertEquals(String.format("Incorrect score for image id %s", expectedItem.get("image_id")), e.getValue(), testScores.get(e.getKey())); }//from w w w.j ava 2 s . c o m } }