List of usage examples for org.json.simple JSONArray size
public int size()
From source file:de.mpg.imeji.presentation.servlet.autocompleter.java
/** * Parse a JSON file from CoNE with authors, and return a JSON which can be read by imeji autocomplete * /* www . j a va 2 s .c o m*/ * @param cone * @return * @throws IOException */ @SuppressWarnings("unchecked") private String parseConeAuthor(String cone) throws IOException { Object obj = JSONValue.parse(cone); JSONArray array = (JSONArray) obj; JSONArray result = new JSONArray(); for (int i = 0; i < array.size(); ++i) { JSONObject parseObject = (JSONObject) array.get(i); JSONObject sendObject = new JSONObject(); sendObject.put("label", parseObject.get("http_purl_org_dc_elements_1_1_title")); sendObject.put("family", parseObject.get("http_xmlns_com_foaf_0_1_family_name")); sendObject.put("givenname", parseObject.get("http_xmlns_com_foaf_0_1_givenname")); sendObject.put("id", parseObject.get("id")); sendObject.put("orgs", writeJsonArrayToOneString(parseObject.get("http_purl_org_escidoc_metadata_terms_0_1_position"), "http_purl_org_eprint_terms_affiliatedInstitution")); sendObject.put("alternatives", writeJsonArrayToOneString(parseObject.get("http_purl_org_dc_terms_alternative"), "")); result.add(sendObject); } StringWriter out = new StringWriter(); JSONArray.writeJSONString(result, out); return out.toString(); }
From source file:eu.hansolo.accs.RestClient.java
private void updateLocations() { locationList.clear();//from www .ja v a 2 s. c o m JSONArray locationsArray = getAllLocations(); for (int i = 0; i < locationsArray.size(); i++) { JSONObject jsonLocation = (JSONObject) locationsArray.get(i); locationList.add(new Location(jsonLocation)); } }
From source file:com.asus.ctc.eebot.ie.externalresources.conceptnet.JsonDecoder.java
/** * This code extracts the edges from json; * //from www . ja v a 2s . c o m * @param edges * @return */ private ConceptNetDataStructure createConceptNetEdges(Object edges) { ConceptNetDataStructure cds = new ConceptNetDataStructure(); List<ConceptNetEdge> edgeList = new LinkedList<ConceptNetEdge>(); String conceptDescription = ""; JSONArray edgeJsonArray = (JSONArray) edges; for (int i = 0; i < edgeJsonArray.size(); i++) { JSONObject jobj = (JSONObject) edgeJsonArray.get(i); String start = (String) jobj.get("start"); String rel = (String) jobj.get("rel"); String end = (String) jobj.get("end"); if (start.contains("/c/en/")) { start = start.replace("/c/en/", ""); } if (end.contains("/c/en/")) { end = end.replace("/c/en/", ""); } if (rel.contains("/r/")) { rel = rel.replace("/r/", ""); } ConceptNetEdge edge = new ConceptNetEdge(); edge.setStart(start); edge.setRel(rel); edge.setEnd(end); createEdgeNLG(edge); edgeList.add(edge); conceptDescription += edge.getNlg() + ". "; // System.out.println(start + " " + rel + " "+ end); } cds.setEdges(edgeList); cds.setConceptDescription(conceptDescription); return cds; }
From source file:com.rackspacecloud.blueflood.outputs.serializers.JSONBasicRollupOutputSerializerTest.java
@Test public void testEnums() throws Exception { final JSONBasicRollupsOutputSerializer serializer = new JSONBasicRollupsOutputSerializer(); final MetricData metricData = new MetricData(FakeMetricDataGenerator.generateFakeEnumRollupPoints(), "unknown", MetricData.Type.ENUM); JSONObject metricDataJSON = serializer.transformRollupData(metricData, PlotRequestParser.DEFAULT_STATS); final JSONArray data = (JSONArray) metricDataJSON.get("values"); Assert.assertEquals(5, data.size()); for (int i = 0; i < data.size(); i++) { final JSONObject dataJSON = (JSONObject) data.get(i); final Map<String, Long> evJSON = (Map<String, Long>) dataJSON.get("enum_values"); Set<String> keys = evJSON.keySet(); Assert.assertEquals(1, keys.size()); for (String key : keys) { Assert.assertEquals(key, "enum_value_" + i); Assert.assertEquals((long) evJSON.get(key), 1); }//from w w w . j a va2 s .co m Assert.assertNotNull(dataJSON.get("numPoints")); Assert.assertEquals(1, dataJSON.get("numPoints")); Assert.assertEquals(MetricData.Type.ENUM, dataJSON.get("type")); } }
From source file:com.rackspacecloud.blueflood.outputs.serializers.JSONBasicRollupOutputSerializerTest.java
@Test public void testGauges() throws Exception { final JSONBasicRollupsOutputSerializer serializer = new JSONBasicRollupsOutputSerializer(); final MetricData metricData = new MetricData(FakeMetricDataGenerator.generateFakeGaugeRollups(), "unknown", MetricData.Type.NUMBER); JSONObject metricDataJSON = serializer.transformRollupData(metricData, PlotRequestParser.DEFAULT_GAUGE); final JSONArray data = (JSONArray) metricDataJSON.get("values"); Assert.assertEquals(5, data.size()); for (int i = 0; i < data.size(); i++) { final JSONObject dataJSON = (JSONObject) data.get(i); Assert.assertNotNull(dataJSON.get("numPoints")); Assert.assertEquals(1L, dataJSON.get("numPoints")); Assert.assertNotNull("latest"); Assert.assertEquals(i, dataJSON.get("latest")); // other fields were filtered out. Assert.assertNull(dataJSON.get(MetricStat.AVERAGE.toString())); Assert.assertNull(dataJSON.get(MetricStat.VARIANCE.toString())); Assert.assertNull(dataJSON.get(MetricStat.MIN.toString())); Assert.assertNull(dataJSON.get(MetricStat.MAX.toString())); }//from w w w . ja v a 2 s. c om }
From source file:functionaltests.RestSchedulerJobPaginationTest.java
private JSONObject findJob(String id, JSONArray jobs) { for (int i = 0; i < jobs.size(); i++) { if (((JSONObject) jobs.get(i)).get("jobid").equals(id)) { return (JSONObject) jobs.get(i); }/* w w w . ja va2 s . c o m*/ } Assert.fail("Failed to find job " + id + ", all jobs: " + jobs); return null; }
From source file:com.walmartlabs.mupd8.application.Config.java
@SuppressWarnings("unchecked") private void loadAppConfig(String filename) throws Exception { JSONObject appJson = (JSONObject) JSONValue.parse(readWithPreprocessing(new FileReader(filename))); JSONObject applicationNameObject = new JSONObject(); String applicationName = (String) appJson.get("application"); applicationNameObject.put(applicationName, appJson); JSONObject mupd8 = (JSONObject) configuration.get("mupd8"); mupd8.put("application", applicationNameObject); if (appJson.containsKey("performers")) { JSONArray performers = (JSONArray) appJson.get("performers"); for (int i = 0; i < performers.size(); i++) { JSONObject json = (JSONObject) performers.get(i); String performer = (String) json.get("performer"); workerJSONs.put(performer, json); }/*from w w w.j a v a 2 s . c o m*/ } }
From source file:edu.emory.library.spotlight.SpotlightClient.java
public List<SpotlightAnnotation> annotate(String txt) throws Exception { List<SpotlightAnnotation> annotations = new ArrayList<SpotlightAnnotation>(); try {/*from w w w .j ava2s . c o m*/ String uri = String.format("%s/annotate", this.baseUrl); HashMap headers = new HashMap<String, String>(); headers.put("Accept", "application/json"); // content-type required when using POST headers.put("Content-Type", "application/x-www-form-urlencoded"); HashMap params = new HashMap<String, String>(); params.put("text", txt); // restrict to supported types (TODO: don't hard-code here; configurable?) params.put("types", "Person,Place,Organisation"); // include confidence & support parameters if set if (this.confidence != null) { params.put("confidence", String.format("%s", this.confidence)); } if (this.support != null) { params.put("support", String.format("%d", this.support)); } // always use POST to support text larger than that allowed in // an HTTP GET request URI String response = EULHttpUtils.postUrlContents(uri, headers, params); // load the result as json JSONObject json = (JSONObject) new JSONParser().parse(response); // information about identified names are listed under 'Resources' JSONArray jsonArray = (JSONArray) json.get("Resources"); // if no names are identified, resources will not be set if (jsonArray != null) { for (int i = 0; i < jsonArray.size(); i++) { SpotlightAnnotation sa = new SpotlightAnnotation((JSONObject) jsonArray.get(i)); annotations.add(sa); } } } catch (java.io.UnsupportedEncodingException e) { // TODO: log error instead of just printing System.out.println("Error encoding text"); } // TODO: also need to catch json decoding error return annotations; }
From source file:de.tuttas.config.Config.java
/** /* w ww .j a v a2s . c o m*/ */ private Config() { BufferedReader br = null; try { String pathConfig = System.getProperty("catalina.base") + File.separator + "config.json"; br = new BufferedReader(new FileReader(pathConfig)); StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } String conf = sb.toString(); JSONParser parser = new JSONParser(); JSONObject jo = (JSONObject) parser.parse(conf); debug = (boolean) jo.get("debug"); auth = (boolean) jo.get("auth"); IMAGE_FILE_PATH = (String) jo.get("IMAGE_FILE_PATH"); ATEST_FILE_PATH = (String) jo.get("ATEST_FILE_PATH"); TEMPLATE_FILE_PATH = (String) jo.get("TEMPLATE_FILE_PATH"); Log.d("IMage_File_Path=" + IMAGE_FILE_PATH); JSONArray ja = (JSONArray) jo.get("adminusers"); adminusers = new String[ja.size()]; for (int i = 0; i < adminusers.length; i++) { adminusers[i] = (String) ja.get(i); } ja = (JSONArray) jo.get("verwaltung"); verwaltung = new String[ja.size()]; for (int i = 0; i < verwaltung.length; i++) { verwaltung[i] = (String) ja.get(i); Log.d("Setzte Verwaltung " + (String) ja.get(i)); } AUTH_TOKE_TIMEOUT = (long) jo.get("AUTH_TOKE_TIMEOUT"); // LDAP Konfiguration ldaphost = (String) jo.get("ldaphost"); bindUser = (String) jo.get("binduser"); bindPassword = (String) jo.get("bindpassword"); userContext = (String) jo.get("context"); // SMTP Server Konfiguration smtphost = (String) jo.get("smtphost"); port = (String) jo.get("port"); user = (String) jo.get("user"); pass = (String) jo.get("pass"); // Client Configuration clientConfig = (JSONObject) jo.get("clientConfig"); clientConfig.put("VERSION", Config.VERSION); } catch (UnsupportedEncodingException ex) { Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex); ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException ex) { ex.printStackTrace(); Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (br != null) br.close(); } catch (IOException ex) { Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.optimizely.ab.config.parser.JsonSimpleConfigParser.java
private List<TrafficAllocation> parseTrafficAllocation(JSONArray trafficAllocationJson) { List<TrafficAllocation> trafficAllocation = new ArrayList<TrafficAllocation>(trafficAllocationJson.size()); for (Object obj : trafficAllocationJson) { JSONObject allocationObject = (JSONObject) obj; String entityId = (String) allocationObject.get("entityId"); long endOfRange = (Long) allocationObject.get("endOfRange"); trafficAllocation.add(new TrafficAllocation(entityId, (int) endOfRange)); }//from w ww.j a v a 2s .c o m return trafficAllocation; }