List of usage examples for org.json.simple JSONArray size
public int size()
From source file:edu.anu.spice.SpiceScorer.java
public void scoreBatch(SpiceArguments args) throws IOException, ScriptException { Stopwatch timer = Stopwatch.createStarted(); SpiceParser parser = new SpiceParser(args.cache, args.numThreads, args.synsets); // Build filters for tuple categories Map<String, TupleFilter> filters = new HashMap<String, TupleFilter>(); if (args.tupleSubsets) { filters.put("Object", TupleFilter.objectFilter); filters.put("Attribute", TupleFilter.attributeFilter); filters.put("Relation", TupleFilter.relationFilter); filters.put("Cardinality", TupleFilter.cardinalityFilter); filters.put("Color", TupleFilter.colorFilter); filters.put("Size", TupleFilter.sizeFilter); }/*from www .j av a 2 s .c o m*/ // Parse test and refs from input file ArrayList<Object> image_ids = new ArrayList<Object>(); ArrayList<String> testCaptions = new ArrayList<String>(); ArrayList<String> refCaptions = new ArrayList<String>(); ArrayList<Integer> refChunks = new ArrayList<Integer>(); JSONParser json = new JSONParser(); JSONArray input; try { input = (JSONArray) json.parse(new FileReader(args.inputPath)); for (Object o : input) { JSONObject item = (JSONObject) o; image_ids.add(item.get("image_id")); testCaptions.add((String) item.get("test")); JSONArray refs = (JSONArray) item.get("refs"); refChunks.add(refs.size()); for (Object ref : refs) { refCaptions.add((String) ref); } } } catch (ParseException e) { System.err.println("Could not read input: " + args.inputPath); System.err.println(e.toString()); e.printStackTrace(); } System.err.println("Parsing reference captions"); List<SceneGraph> refSgs = parser.parseCaptions(refCaptions, refChunks); System.err.println("Parsing test captions"); List<SceneGraph> testSgs = parser.parseCaptions(testCaptions); this.stats = new SpiceStats(filters, args.detailed); for (int i = 0; i < testSgs.size(); ++i) { this.stats.score(image_ids.get(i), testSgs.get(i), refSgs.get(i), args.synsets); } if (!args.silent) { System.out.println(this.stats.toString()); } if (args.outputPath != null) { BufferedWriter outputWriter = new BufferedWriter(new FileWriter(args.outputPath)); // Pretty print output using javascript String jsonStringNoWhitespace = this.stats.toJSONString(); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine scriptEngine = manager.getEngineByName("JavaScript"); scriptEngine.put("jsonString", jsonStringNoWhitespace); scriptEngine.eval("result = JSON.stringify(JSON.parse(jsonString), null, 2)"); String prettyPrintedJson = (String) scriptEngine.get("result"); outputWriter.write(prettyPrintedJson); outputWriter.close(); } System.out.println("SPICE evaluation took: " + timer.stop()); }
From source file:interfaceTisseoWS.ST4.java
public final void init() throws ParseException, IOException, URISyntaxException { RequestJCDecaux r = new RequestJCDecaux(); JSONParser parser = new JSONParser(); r.setPathURIB("/vls/v1/stations"); Object obj = parser.parse(r.request()); JSONArray array = (JSONArray) obj; int nbStations = array.size(); DefaultListModel lm = new DefaultListModel(); for (int i = 0; i < nbStations; i++) { stations.add(new Station((JSONObject) array.get(i))); lm.addElement(stations.get(i).getName()); }// w w w . j ava 2 s . co m listeStations.setModel(lm); }
From source file:models.ACLRole.java
/** * @return never null// w ww. ja v a2s . c o m */ public List<String> getPrivilegesList() { if (privileges == null) { return new ArrayList<String>(1); } if (privileges.trim().equals("")) { return new ArrayList<String>(1); } JSONParser jp = new JSONParser(); try { JSONArray ja = (JSONArray) jp.parse(privileges); if (ja.size() == 0) { return new ArrayList<String>(1); } ArrayList<String> result = new ArrayList<String>(); for (Object o : ja) { result.add((String) o); } return result; } catch (Exception e) { Log2.log.error("Can't extract privileges from DB", e, new Log2Dump("raw privileges", privileges)); return new ArrayList<String>(1); } }
From source file:StudentsUpdate.java
private void getStud(String result) { System.out.println("result ==>" + result); try {/*from w w w.j a v a 2 s . co m*/ 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: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 ww .jav a 2 s . com*/ final TextView textView = (TextView) findViewById(R.id.textView); textView.setText(result); }
From source file:models.ACLRole.java
/** * @return never null// w w w .j a v a 2 s. c o m */ public List<String> getFunctionalitiesList() { if (functionalities == null) { return new ArrayList<String>(1); } if (functionalities.trim().equals("")) { return new ArrayList<String>(1); } JSONParser jp = new JSONParser(); try { JSONArray ja = (JSONArray) jp.parse(functionalities); if (ja.size() == 0) { return new ArrayList<String>(1); } ArrayList<String> result = new ArrayList<String>(); for (Object o : ja) { result.add((String) o); } return result; } catch (Exception e) { Log2.log.error("Can't extract functionalities from DB", e, new Log2Dump("raw functionalities", functionalities)); return new ArrayList<String>(1); } }
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 av a2 s . co m*/ } }
From source file:buspathcontroller.JSONFileParser.java
public void generateRouteStopsAndPath() { JSONParser parser = new JSONParser(); ArrayList<String> routeList = new ArrayList<String>(); try {/*w ww . j a v a2 s. co m*/ FileReader reader = new FileReader("/Users/Zhaowei/Desktop/BusPath/allRoutes.txt"); BufferedReader br = new BufferedReader(reader); String line; while ((line = br.readLine()) != null) { String routeName = line.split(";")[1]; routeList.add(routeName); } br.close(); reader.close(); Iterator<String> it = routeList.iterator(); while (it.hasNext()) { String routeName = it.next(); PrintWriter writer = new PrintWriter( "/Users/Zhaowei/Desktop/BusPath/routeInfo/stops/" + routeName + ".txt"); Object obj = parser.parse( new FileReader("/Users/Zhaowei/Desktop/BusPath/RawJSON/route/" + routeName + ".json")); JSONObject jsonObject = (JSONObject) obj; JSONObject route = (JSONObject) jsonObject.get("route"); JSONArray directions = (JSONArray) route.get("directions"); for (int i = 0; i < directions.size(); i++) { JSONObject direction = (JSONObject) directions.get(i); writer.println(direction.get("direction")); JSONArray stops = (JSONArray) direction.get("stops"); Iterator iter = stops.iterator(); while (iter.hasNext()) { JSONObject stop = (JSONObject) iter.next(); writer.println(stop.get("stopnumber") + ";" + stop.get("stoptitle") + ";" + stop.get("stoplat") + ";" + stop.get("stoplng")); } } writer.close(); } } catch (Exception e) { System.out.println(e); } }
From source file:com.shazam.dataengineering.pipelinebuilder.Deployment.java
public Deployment(JSONObject obj) { this.username = (String) obj.get("username"); this.status = (Boolean) obj.get("status"); this.pipelineId = (String) obj.get("pipelineId"); this.date = new Date((Long) obj.get("date")); JSONArray messageArray = (JSONArray) obj.get("messages"); this.messages = new ArrayList<String>(); for (int i = 0; i < messageArray.size(); i++) { this.messages.add((String) messageArray.get(i)); }/* w w w. jav a 2 s. c o m*/ }
From source file:control.ProcesoVertimientosServlets.RegistrarTasaRetibutiva.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/* w ww .j a va2s .c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int codigoProceso = Integer.parseInt(request.getParameter("codigoProceso")); String cargasParam = request.getParameter("cargasParam"); String valorTasaCobrada = request.getParameter("valorTasaCobrada"); String valorTotalTasaPagar = request.getParameter("valorTotalTasaPagar"); Object obj = JSONValue.parse(cargasParam); JSONArray jsonArray = new JSONArray(); jsonArray = (JSONArray) obj; for (int i = 0; i < jsonArray.size(); i++) { //Obtenemos los valores por parametro JSONObject jsonObject = (JSONObject) jsonArray.get(i); String valorTarifa = (String) jsonObject.get("valorTarifa"); String procentajeRemocion = (String) jsonObject.get("procentajeRemocion"); String valorTasa = (String) jsonObject.get("valorTasa"); String valorCarga = (String) jsonObject.get("valorCarga"); String codigoParametro = (String) jsonObject.get("codigoParametro"); try { //Creamos el manager y guardamos la informacion. ProgramarMonitoreo manager = new ProgramarMonitoreo(); manager.registrarTasaRetributiva(codigoProceso, Integer.parseInt(codigoParametro), valorTarifa, procentajeRemocion, valorTasa, valorCarga, valorTasaCobrada, valorTotalTasaPagar); } catch (Exception ex) { } } String codigoParametro = ""; String valorTarifa = request.getParameter("codigoProceso"); String procentajeRemocion = request.getParameter("codigoProceso"); String valorTasa = request.getParameter("codigoProceso"); String valorCarga = request.getParameter("codigoProceso"); }