List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:com.bigml.histogram.NumericTarget.java
@Override @SuppressWarnings("unchecked") protected void addJSON(JSONArray binJSON, DecimalFormat format) { if (_sum == null) { binJSON.add(null); } else {// w w w . j a v a 2 s . co m binJSON.add(Utils.roundNumber(_sum, format)); binJSON.add(Utils.roundNumber(_sumSquares, format)); } }
From source file:bookUtilities.PopulateMyBooksServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * * @param request servlet request//ww w.j av a 2 s . c om * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); String email; email = (String) request.getSession().getAttribute("email"); JSONArray fileTypes = new JSONArray(); JSONArray userBooks = getUserBooks(email, fileTypes); JSONArray infoToPush = new JSONArray(); infoToPush.add(userBooks); infoToPush.add(fileTypes); PrintWriter printout = response.getWriter(); printout.print(infoToPush); printout.flush(); }
From source file:control.ParametrizacionServlets.InsertarAsociacionContratos.java
/** * //from www. j a v a 2 s . c o m * Escribe el string de JSON para enviarlo a la vista * * @param response * @param errores * @throws IOException */ private void escribirJSON(HttpServletResponse response) throws IOException { JSONArray arrayResp = new JSONArray(); arrayResp.add(arrayErrores); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object json : arrayResp) { response.getWriter().write(json.toString()); } }
From source file:com.shazam.dataengineering.pipelinebuilder.Deployment.java
public JSONObject toJSON() { JSONArray messageArray = new JSONArray(); for (String message : messages) { messageArray.add(message); }// w w w . ja v a 2s.c om JSONObject deployment = new JSONObject(); deployment.put("username", username); deployment.put("status", status); deployment.put("pipelineId", pipelineId); deployment.put("date", date.getTime()); deployment.put("messages", messageArray); return deployment; }
From source file:model.SummaryList.java
public JSONArray toJSON() { JSONArray json = new JSONArray(); for (Summary s : summaryList) { json.add(s.toJSON()); }//from w ww . j a v a 2s . co m return json; }
From source file:control.ParametrizacionServlets.ActualizarAsociacionContratos.java
/** * /*from w ww.j av a 2 s .com*/ * Escribe el string de JSON para enviarlo a la vista * * @param response * @param errores * @throws IOException */ private void escribirJSON(HttpServletResponse response) throws IOException { JSONArray arrayResp = new JSONArray(); arrayResp.add(arrayErrores); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object json : arrayResp) { response.getWriter().write(json.toString()); } }
From source file:analysers.ExportValidated.java
/** * Make a list of all daughter cells./*from ww w . ja v a 2 s . co m*/ * * Also fix the lineage links. * * @param a The ancestral cell * @param l a list of all daughter cells * @param names a map of cell names * @param pname the name prefix * @param divns JSONArray of division frames */ @SuppressWarnings("unchecked") public static void getAllDaughters(Cell a, List<Cell> l, Map<Integer, String> names, String pname, JSONArray divns) { int k = 1; if (pname == null) { pname = "Cell 1"; } names.put(new Integer(a.getCellID()), pname); Cell p = null; while (a != null) { // fix links if (p != null) { a.setPreviousCell(p); p.setNextCell(a); } Cell d = a.getDaughterCell(); if (d != null) { // fix, just in case. d.setPreviousCell(a); divns.add(new Integer(a.getFrame() + 1)); l.add(d); getAllDaughters(d, l, names, pname + "-" + k, divns); k++; } p = a; a = a.getNextCell(); } }
From source file:com.mycompany.rent.controllers.MapController.java
@RequestMapping(value = "/data", method = RequestMethod.GET) public File homePage(Map model) throws IOException { List<ForRent> allRentals = new ArrayList(); allRentals = forRentDao.allRentals(); JSONObject responseDetailsJson = new JSONObject(); JSONArray array = new JSONArray(); for (ForRent f : allRentals) { array.add(f.getLat()); array.add(f.getLon());//from ww w . j a v a 2 s .c o m } responseDetailsJson.put("data", (Object) array);//Here you can see the data in json format File file = new File("/home/brennan/_repos/rent/src/main/webapp/json/data.json"); String path = file.getPath(); try { // Writing to a file file.createNewFile(); FileWriter fileWriter = new FileWriter(file); fileWriter.write(responseDetailsJson.toJSONString()); fileWriter.flush(); fileWriter.close(); } catch (IOException e) { } FileReader fr = new FileReader(file); return file; }
From source file:cat.tv3.eng.rec.recomana.lupa.visualization.ClustersToJson.java
public static JSONArray hashToJSONArrayRepresentationBinaryTree(String id, String hash, Jedis jedis, String id2, String hash2) {/*ww w .j a va 2 s. com*/ JSONArray result = new JSONArray(); JSONObject info; Map<String, String> attr_cluster = jedis.hgetAll(hash); String cluster_name = attr_cluster.get("cluster_ids_name"); if (!cluster_name.equals("cluster_splited")) { info = new JSONObject(); info.put("name", "Centroid " + id); String[] instance_group_keys = jedis.keys("Instances_centroid_ID_" + id).toArray(new String[0]); info.put("children", fullestoArray(instance_group_keys, jedis)); } else { String id_left_centroid = attr_cluster.get("id_left_centroid"); String id_right_centroid = attr_cluster.get("id_right_centroid"); String hash_left = attr_cluster.get("hash_left"); String hash_right = attr_cluster.get("hash_right"); info = new JSONObject(); info.put("name", "Centroid " + id); info.put("children", hashToJSONArrayRepresentationBinaryTree(id_left_centroid, hash_left, jedis, id_right_centroid, hash_right)); } result.add(info); attr_cluster = jedis.hgetAll(hash2); cluster_name = attr_cluster.get("cluster_ids_name"); if (!cluster_name.equals("cluster_splited")) { info = new JSONObject(); info.put("name", "Centroid " + id2); String[] instance_group_keys = jedis.keys("Instances_centroid_ID_" + id2).toArray(new String[0]); info.put("children", fullestoArray(instance_group_keys, jedis)); } else { String id_left_centroid = attr_cluster.get("id_left_centroid"); String id_right_centroid = attr_cluster.get("id_right_centroid"); String hash_left = attr_cluster.get("hash_left"); String hash_right = attr_cluster.get("hash_right"); info = new JSONObject(); info.put("name", "Centroid " + id2); info.put("children", hashToJSONArrayRepresentationBinaryTree(id_left_centroid, hash_left, jedis, id_right_centroid, hash_right)); } result.add(info); return result; }
From source file:com.conwet.silbops.model.AdvertiseTest.java
@Test @SuppressWarnings({ "unchecked" }) public void testJSONExport() { JSONArray json = new JSONArray(); json.add("attr1:double"); json.add("attr2:long"); json.add("attr3:str"); JSONArray newJSON = advertise.toJSON(); Collections.sort(newJSON);/*from www. j av a 2s . c om*/ Collections.sort(json); assertThat(newJSON).isEqualTo(json); assertThat(Advertise.fromJSON(json)).isEqualTo(advertise); }