List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:com.appzone.sim.services.handlers.MtLogCheckServiceHandler.java
@Override protected String doProcess(HttpServletRequest request) { String sinceStr = request.getParameter(KEY_SINCE); logger.debug("request mt logs since: {}", sinceStr); long since = Long.parseLong(sinceStr); List<MtMessage> messages = mtMessageRepository.find(since); JSONArray list = new JSONArray(); for (MtMessage mtMessage : messages) { String message = mtMessage.getMessage(); String addresses = JSONValue.toJSONString(mtMessage.getAddresses()); String receivedDate = "" + mtMessage.getReceivedDate(); JSONObject json = new JSONObject(); json.put(JSON_KEY_MESSAGE, message); json.put(JSON_KEY_ADDRESSES, JSONValue.parse(addresses)); json.put(JSON_KEY_RECEIVED_DATE, receivedDate); list.add(json); }/*from w w w. j a va2 s .c o m*/ logger.debug("returning response: {}", list); return list.toJSONString(); }
From source file:CPD4414Assign3.ProductServlet.java
private String getResults(String query, String... params) { StringBuilder results = new StringBuilder(); String result = "a"; try (Connection conn = getConnection()) { PreparedStatement pstmt = conn.prepareStatement(query); for (int i = 1; i <= params.length; i++) { pstmt.setString(i, params[i - 1]); }/*from ww w . j a va2 s.co m*/ ResultSet rs = pstmt.executeQuery(); JSONObject resultObj = new JSONObject(); JSONArray productArr = new JSONArray(); while (rs.next()) { Map productMap = new LinkedHashMap(); productMap.put("productID", rs.getInt("productID")); productMap.put("name", rs.getString("name")); productMap.put("description", rs.getString("description")); productMap.put("quantity", rs.getInt("quantity")); productArr.add(productMap); } resultObj.put("product", productArr); result = resultObj.toString(); } catch (SQLException ex) { Logger.getLogger(ProductServlet.class.getName()).log(Level.SEVERE, null, ex); } return result; }
From source file:com.Assignment4.Assign.java
@GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON)/*from w w w . ja v a 2s . c om*/ public String getproduct(@PathParam("id") int id) throws SQLException { if (connected == null) { return "not connected"; } else { String query = "Select * from product where product_id = ?"; PreparedStatement pstmt = connected.prepareStatement(query); pstmt.setInt(1, id); ResultSet rs = pstmt.executeQuery(); String res = ""; JSONArray productArr = new JSONArray(); while (rs.next()) { Map proMap = new LinkedHashMap(); proMap.put("productID", rs.getInt("product_id")); proMap.put("name", rs.getString("name")); proMap.put("description", rs.getString("description")); proMap.put("quantity", rs.getInt("quantity")); productArr.add(proMap); } res = productArr.toString(); return res; } }
From source file:com.imagelake.control.KeyWordsDAOImp.java
public JSONArray getJSONAllKeyWords() { JSONArray ja = new JSONArray(); try {// w ww. j av a 2 s. com String sql = "SELECT * FROM key_words GROUP BY key_word"; PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ResultSet rs = ps.executeQuery(); while (rs.next()) { JSONObject jo = new JSONObject(); jo.put("id", rs.getInt(1)); jo.put("kw", rs.getString(2)); ja.add(jo); } } catch (Exception e) { e.printStackTrace(); } return ja; }
From source file:com.product.Product.java
@GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON)/*from w ww. j a v a2 s .co m*/ public String getproduct(@PathParam("id") int id) throws SQLException { if (connect == null) { return "not connected"; } else { String query = "Select * from products where product_id = ?"; PreparedStatement prepstmnt = connect.prepareStatement(query); prepstmnt.setInt(1, id); ResultSet rs = prepstmnt.executeQuery(); String result = ""; JSONArray prodArr = new JSONArray(); while (rs.next()) { Map prodMap = new LinkedHashMap(); prodMap.put("productID", rs.getInt("product_id")); prodMap.put("name", rs.getString("name")); prodMap.put("description", rs.getString("description")); prodMap.put("quantity", rs.getInt("quantity")); prodArr.add(prodMap); } result = prodArr.toString(); return result; } }
From source file:modelo.UsuariosManagers.Roles.java
public JSONArray getRoles(String usuario, String rol, String codigo) throws SQLException { SeleccionarRoles select = new SeleccionarRoles(); ResultSet rset = select.getRoles(codigo, usuario); //Creamos los JSONArray para guardar los objetos JSON JSONArray jsonArray = new JSONArray(); JSONArray jsonArreglo = new JSONArray(); //Recorremos el ResultSet, armamos el objeto JSON con la info y guardamos en el JSONArray. while (rset.next()) { //Armamos el objeto JSON con la informacion del registro JSONObject jsonObject = new JSONObject(); jsonObject.put("codigo", rset.getString("PK_CODIGO")); jsonObject.put("descripcion", rset.getString("VAR_ROL")); //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista. jsonArray.add(jsonObject.clone()); }/*from w ww.ja va2 s. co m*/ select.desconectar(); jsonArreglo.add(jsonArray); return jsonArreglo; }
From source file:com.dubture.symfony.ui.preferences.ServiceConfigurationBlock.java
protected final void updateModel(DialogField field) { if (field == serviceList) { List list = serviceList.getElements(); JSONArray data = new JSONArray(); for (int i = 0; i < list.size(); i++) { SyntheticService elem = (SyntheticService) list.get(i); JSONObject jsonService = JsonUtils.createService(elem.name, elem.className); data.add(jsonService); }//from w w w . j ava2s .com setValue(SYNTHETIC_SERVICES, data.toString()); validateSettings(SYNTHETIC_SERVICES, null, null); } }
From source file:name.yumaa.ChromeLogger4J.java
/** * Adds a value to the data array/*from w w w. j a v a 2 s. c o m*/ * @param log log data * @param backtrace backtrace data * @param type log type */ private void addRow(JSONArray log, String backtrace, String type) { if (backtraces.contains(backtrace)) backtrace = null; else if (backtrace != null) backtraces.add(backtrace); JSONArray row = new JSONArray(); row.add(log); row.add(backtrace); row.add(type); ((JSONArray) json.get("rows")).add(row); }
From source file:edu.anu.spice.SpiceStats.java
@SuppressWarnings("unchecked") public JSONArray toJSONArray() { JSONArray array = new JSONArray(); for (int i = 0; i < this.imageIds.size(); ++i) { JSONObject jsonObj = new JSONObject(); jsonObj.put("image_id", this.imageIds.get(i)); jsonObj.put("scores", new JSONObject(this.scores.get(i))); if (this.isDetailed) { jsonObj.put("test_tuples", this.testTuples.get(i)); jsonObj.put("ref_tuples", this.refTuples.get(i)); }//from w w w.j a v a 2 s. c om array.add(jsonObj); } return array; }
From source file:cc.siara.csv_ml.ParsedObject.java
/** * Adds new JSONObject and makes it current * //from w ww. ja v a 2 s . co m * @param node_name * Name of new JSONObject to be created */ private void addNewJO(String node_name) { JSONObject new_node = null; if (cur_jo.get(node_name) == null) { cur_jo.put(node_name, new JSONArray()); } // Each node is assumed to be an array having multiple data elements JSONArray ja = (JSONArray) cur_jo.get(node_name); new_node = new JSONObject(); // Keep a reference to the parent, so that we can go up the level new_node.put("parent_ref", cur_jo); ja.add(new_node); cur_jo = new_node; last_jo = cur_jo; }