List of usage examples for org.json.simple JSONArray iterator
public Iterator<E> iterator()
From source file:com.github.lgi2p.obirs.utils.JSONConverter.java
public static ObirsQuery parseObirsJSONQuery(SM_Engine engine, String jsonQuery) throws ParseException, Exception { logger.info("parsing query: " + jsonQuery); URIFactory factory = URIFactoryMemory.getSingleton(); jsonQuery = jsonQuery.replace("\n", ""); jsonQuery = jsonQuery.replace("\r", ""); JSONParser parser = new JSONParser(); Object obj = parser.parse(jsonQuery); JSONObject jsonObject = (JSONObject) obj; String aggregator = (String) jsonObject.get("aggregator"); String similarityMeasure = (String) jsonObject.get("similarityMeasure"); Double aggregatorParameter;//w w w.j a va 2 s . c om if (jsonObject.get("aggregatorParameter") != null) { aggregatorParameter = Double.parseDouble(jsonObject.get("aggregatorParameter").toString()); } else { aggregatorParameter = 2.0; } Double scoreThreshold = (Double) jsonObject.get("scoreThreshold"); Integer numberOfResults = (Integer) jsonObject.get("numberOfResults"); JSONArray concepts = (JSONArray) jsonObject.get("concepts"); Map<URI, Double> conceptsMap = new HashMap<URI, Double>(); ObirsQuery query = new ObirsQuery(conceptsMap, aggregator, similarityMeasure, aggregatorParameter, scoreThreshold, numberOfResults); if (concepts != null) { Iterator<JSONObject> iterator = concepts.iterator(); while (iterator.hasNext()) { JSONObject concept = iterator.next(); Double weight = Double.parseDouble(concept.get("weight").toString()); Object uriString = concept.get("uri"); if (uriString == null) { throw new SLIB_Ex_Critic("Error a URI must be specified for each query concept"); } URI uri = factory.getURI(uriString.toString()); if (engine.getGraph().containsVertex(uri)) { query.addConcept(uri, weight); } else { throw new Exception("concept associated to URI '" + uri + "' does not exists..."); } } } return query; }
From source file:com.storageroomapp.client.PageOfEntries.java
/** * Unmarshalls an PageOfEntries object from a JSONObject. This method * assumes the name-values are immediately attached to the passed object * and not nested under a key (e.g. 'array') * @param jsonObj the JSONObject//from w ww . j av a2 s .c o m * @return an PageOfEntries object, or null if the unpacking failed */ static public PageOfEntries parseJSONObject(Collection parent, JSONObject jsonObject) { if (jsonObject == null) { return null; } JSONArray jsonArray = (JSONArray) jsonObject.get("resources"); if (jsonArray == null) { return null; } PageOfEntries el = new PageOfEntries(); el.currentPage = JsonSimpleUtil.parseJsonIntValue(jsonObject, "@page", 0); el.currentPageSize = JsonSimpleUtil.parseJsonIntValue(jsonObject, "@total_resources", 20); el.numResultsPages = JsonSimpleUtil.parseJsonIntValue(jsonObject, "@pages", 1); el.currentPageEntries = new ArrayList<Entry>(); @SuppressWarnings("unchecked") Iterator<JSONObject> iter = jsonArray.iterator(); while (iter.hasNext()) { JSONObject entryObj = iter.next(); Entry entry = Entry.parseJSONObject(parent, entryObj); if (entry != null) { el.currentPageEntries.add(entry); } } return el; }
From source file:fr.treeptik.cloudunit.docker.DockerContainerJSON.java
private static List<String> getList(JSONObject object, String listName) { List<String> list = new ArrayList<>(); JSONArray node = (JSONArray) object.get(listName); Iterator<String> iterator = node.iterator(); while (iterator.hasNext()) { list.add(iterator.next());//w ww . j a v a2 s. c o m } return list; }
From source file:fr.treeptik.cloudunit.docker.DockerContainerJSON.java
private static List<Object> getObjectList(JSONObject object, String listName) { List<Object> list = new ArrayList<>(); JSONArray node = (JSONArray) object.get(listName); Iterator<Object> iterator = node.iterator(); while (iterator.hasNext()) { list.add(iterator.next());//from w w w.j a v a 2 s. c o m } return list; }
From source file:luceneprueba.utils.FileParser.java
static public void createFilesFromJSONArray() throws IOException { File dir = new File("files/input"); File[] files = dir.listFiles(); if (files == null) { System.out.println("No existe la carpeta \'input\' dentro de la carpeta files."); return;/*from www.j ava 2s .c o m*/ } if (files.length == 0) { System.out.println("No hay ningun archivo en la carpeta \'input\' para ser indexado"); return; } BufferedReader br; String fileContent; JSONArray jsonArray = null; JSONParser jsonParser = new JSONParser(); int i = 1; FileWriter datosReviews = null; try { datosReviews = new FileWriter("files/output/datos_reviews.txt"); } catch (IOException ex) { ex.printStackTrace(System.out); } for (File file : files) { if (file.isFile() && file.canRead() && file.getName().endsWith(".txt")) { System.out.println("Leyendo el archivo: " + file.getName()); FileWriter contentReviews; try { br = new BufferedReader(new FileReader(file)); fileContent = br.readLine(); jsonArray = (JSONArray) jsonParser.parse(fileContent); Iterator it = jsonArray.iterator(); DecimalFormat formato = new DecimalFormat("000000"); while (it.hasNext()) { JSONObject json = (JSONObject) it.next(); if (json.get("Genre") != null && json.get("Date") != null) { contentReviews = new FileWriter( "files/output/clasificador/review_clasificador_" + formato.format(i) + ".txt"); datosReviews.write(Integer.toString(i) + "_" + (String) json.get("Date") + "_" + (String) json.get("Genre") + "_" + (String) json.get("Score") + "\n"); contentReviews.write(Integer.toString(i) + " " + (String) json.get("Review")); i++; contentReviews.close(); } } br.close(); } catch (FileNotFoundException ex) { ex.printStackTrace(System.out); } catch (IOException | ParseException ex) { ex.printStackTrace(System.out); } } } datosReviews.close(); }
From source file:model.Config.java
public void loadQueries(JSONArray queries) { Iterator it = queries.iterator(); while (it.hasNext()) { String value = it.next().toString(); this.queries.add(value); }//from ww w . j ava 2 s .co m }
From source file:model.SearchResponse.java
public void loadMessage(JSONArray messages) { Iterator it = messages.iterator(); this.messages = new ArrayList<>(); while (it.hasNext()) { JSONObject object = (JSONObject) it.next(); Message message = new Message(); message.load(object);// w ww . j a va2s . c om this.messages.add(message); } }
From source file:buspathcontroller.JSONFileParser.java
public void generateAllRoutes() { JSONParser parser = new JSONParser(); try {// w w w . j ava2 s. c om PrintWriter writer = new PrintWriter("/Users/Zhaowei/Desktop/BusPath/allRoutes.txt"); Object obj = parser.parse(new FileReader("/Users/Zhaowei/Desktop/BusPath/RawJSON/RouteList.json")); JSONObject jsonObject = (JSONObject) obj; JSONArray routes = (JSONArray) jsonObject.get("routes"); Iterator iterator = routes.iterator(); while (iterator.hasNext()) { JSONObject route = (JSONObject) ((JSONObject) iterator.next()).get("route"); writer.println(route.get("name") + ";" + route.get("tag") + ";" + route.get("agency")); } writer.close(); } catch (Exception e) { System.out.println(e); } }
From source file:buspathcontroller.JSONFileParser.java
public void generateAllStops() { JSONParser parser = new JSONParser(); try {/* ww w. ja v a 2 s .com*/ PrintWriter writer = new PrintWriter("/Users/Zhaowei/Desktop/BusPath/allStops.txt"); Object obj = parser.parse(new FileReader("/Users/Zhaowei/Desktop/BusPath/RawJSON/StopList.json")); JSONObject jsonObject = (JSONObject) obj; JSONArray routes = (JSONArray) jsonObject.get("stops"); Iterator iterator = routes.iterator(); while (iterator.hasNext()) { JSONObject stop = (JSONObject) ((JSONObject) iterator.next()).get("stop"); 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.greymemory.nab.Labels.java
public void Read(String file_name) { JSONParser parser = new JSONParser(); try {//from w ww . j a va 2s. co 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(); } }