List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:control.ProcesoVertimientosServlets.SeleccionarArchivosVisita.java
private void getArchivosCargados(HttpServletRequest request, HttpServletResponse response) { try {/*from w ww .ja v a 2 s.c om*/ JSONArray jsonArray = new JSONArray(); int codigoVisita = Integer.parseInt(request.getParameter("codigoVisita")); Visitas manager = new Visitas(); jsonArray = manager.getArchivosCargados(codigoVisita, null); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object jsonObject : jsonArray) { response.getWriter().write(jsonObject.toString()); } } catch (Exception e) { } }
From source file:com.shazam.dataengineering.pipelinebuilder.Deployment.java
public JSONObject toJSON() { JSONArray messageArray = new JSONArray(); for (String message : messages) { messageArray.add(message);/*from w ww . ja v a 2s .c o m*/ } 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:gr.aueb.mipmapgui.controller.file.ActionInitialize.java
private void getSavedSchemata() { JSONArray schemaFileArr = new JSONArray(); File schemaDir = new File(Costanti.SERVER_MAIN_FOLDER + Costanti.SERVER_SCHEMATA_FOLDER); String[] schemaFiles = schemaDir.list(); for (String file : schemaFiles) { file = file.substring(0, file.lastIndexOf('.')); schemaFileArr.add(file);// w w w.ja va 2 s . co m } JSONObject.put("savedSchemata", schemaFileArr); }
From source file:control.ProcesoVertimientosServlets.InsertarVerificacionInfoCaracterizacion.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request// www . j av a 2 s . 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 { try { //Obtenemos la cadena con la informacion y la convertimos en un //JSONArray String respuestas = request.getParameter("respuestas"); Integer codigoProceso = Integer.parseInt(request.getParameter("codigoProceso")); Object obj = JSONValue.parse(respuestas); JSONArray jsonArray = new JSONArray(); jsonArray = (JSONArray) obj; //Recorremos el JSONArray y obtenemos la informacion. for (int i = 0; i < jsonArray.size(); i++) { JSONObject jsonObject = (JSONObject) jsonArray.get(i); String checkeado = (String) jsonObject.get("checkeado"); Integer codigo = Integer.parseInt((String) jsonObject.get("codigo")); //Creamos el manager y guardamos la informacion. VerificacionInfoCaracterizacion manager = new VerificacionInfoCaracterizacion(); manager.insertar(checkeado, codigo, codigoProceso); } } catch (Exception ex) { //Logger.getLogger(InsertarActEconomica.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.saludtec.web.GaleriaWeb.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { String servicio = request.getRequestURI().replace("/HCEMed/Galeria/", ""); switch (servicio) { case "guardar": guardarGaleria(request).writeJSONString(out); break; case "editar": editarGaleria(request).writeJSONString(out); break; case "eliminar": eliminarGaleria(request).writeJSONString(out); break; case "traer": traerGaleria(request).writeJSONString(out); break; case "listar": listarGaleria(request).writeJSONString(out); break; default://from ww w .j a va 2s. c om obj = new JSONObject(); objArray = new JSONArray(); obj.put("error", "404 - El servicio " + servicio + " no existe"); objArray.add(obj); objArray.writeJSONString(out); break; } } }
From source file:com.oracle.products.ProductResource.java
/** * Retrieves representation of an instance of com.oracle.products.ProductResource * @return an instance of java.lang.String *///from www.j a v a2 s . c o m @GET @Produces(MediaType.APPLICATION_JSON) public String getAllProducts() throws SQLException { if (conn == null) { return "not connected"; } else { String query = "Select * from product"; PreparedStatement pstmt = conn.prepareStatement(query); ResultSet rs = pstmt.executeQuery(); String result = ""; JSONArray productArr = new JSONArray(); while (rs.next()) { Map productMap = new LinkedHashMap(); productMap.put("productID", rs.getInt("product_id")); productMap.put("name", rs.getString("name")); productMap.put("description", rs.getString("description")); productMap.put("quantity", rs.getInt("quantity")); productArr.add(productMap); } result = productArr.toString(); return result.replace("},", "},\n"); } }
From source file:com.imagelake.android.purchasemanagement.Servlet_purchaseViseImages.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); try {/*from w ww . j a v a 2 s . co m*/ String type = request.getParameter("type"); if (type != null && !type.equals("")) { if (type.equals("all")) { ja = new JSONArray(); li = new CartDAOImp().listdownloadedImages(); Images im; int i = 1; Categories c = null; Cart ct = null; User buyer = null; User Seller = null; if (!li.isEmpty()) { for (CartHasImages cartHasImages : li) { JSONObject jo = new JSONObject(); jo.put("cid", cartHasImages.getImg_id()); im = idi.getImageDetail(cartHasImages.getImg_id()); jo.put("title", im.getTitle()); jo.put("credit", cartHasImages.getCredits()); c = cadi.getCategory(im.getCategories_category_id()); jo.put("category", c.getCategory()); jo.put("date", cartHasImages.getDate()); ct = cdi.getACart(cartHasImages.getCart_id()); buyer = udi.getUser(ct.getUser_id()); Seller = udi.getUser(im.getUser_user_id()); jo.put("buyer", buyer.getUser_name()); jo.put("seller", Seller.getUser_name()); ja.add(jo); } System.out.println(ja.toJSONString()); out.write("json=" + ja.toJSONString()); } else { out.write("msg=No item found."); } } else if (type.equals("all_sort")) { ja = new JSONArray(); List<Categories> cli = cadi.listAllCategories(); JSONArray catAr = new JSONArray(); for (Categories categories : cli) { JSONObject jo = new JSONObject(); jo.put("id", categories.getCategory_id()); jo.put("category", categories.getCategory()); catAr.add(jo); } ja.add(catAr); List<User> usli = udi.listSellersBuyers(); JSONArray usAr = new JSONArray(); for (User user : usli) { JSONObject jo = new JSONObject(); jo.put("bid", user.getUser_id()); jo.put("bun", user.getUser_name()); usAr.add(jo); } ja.add(usAr); List<User> sli = udi.listAllSellers(); JSONArray seAr = new JSONArray(); for (User u : sli) { JSONObject jo = new JSONObject(); jo.put("sid", u.getUser_id()); jo.put("sun", u.getUser_name()); seAr.add(jo); } ja.add(seAr); System.out.println(ja.toJSONString()); out.write("json=" + ja.toJSONString()); } else if (type.equals("sort")) { ja = new JSONArray(); String imid, date, cat, buyer, seller, date2; imid = request.getParameter("imid"); date = request.getParameter("date"); date2 = request.getParameter("date2"); cat = request.getParameter("cat"); buyer = request.getParameter("buy"); seller = request.getParameter("sell"); System.out.println("imgid:" + imid); System.out.println("date:" + date); System.out.println("date2:" + date2); System.out.println("cat:" + cat); System.out.println("buyer:" + buyer); System.out.println("seller:" + seller); String sql = "SELECT SQL_CALC_FOUND_ROWS * FROM cart_has_images"; String where = ""; String tr = ""; if (imid.equals("0")) { imid = ""; } if (cat.equals("0")) { cat = ""; } if (buyer.equals("0")) { buyer = ""; } if (seller.equals("0")) { seller = ""; } if (!imid.equals("") && !imid.equals(null)) { if (where.equals("")) { where += " WHERE is_purchase!='0' AND is_purchase!='2' AND "; sql += where; } sql += " img_id='" + Integer.parseInt(imid) + "'"; if (!date.equals("") && !date.equals(null) && !date2.equals("") && !date2.equals(null) || !cat.equals("") && !cat.equals(null) || !buyer.equals("") && !buyer.equals(null) || !seller.equals("") && !seller.equals(null)) { sql += " AND "; } } if (!date.equals("") && !date.equals(null) && !date2.equals("") && !date2.equals(null)) { if (where.equals("")) { where += " WHERE is_purchase!='0' AND is_purchase!='2' AND "; sql += where; } String[] dt = date.split("-"); String[] dt2 = date2.split("-"); String orDate = dt[2] + "-" + dt[1] + "-" + dt[0]; String orDate2 = dt2[2] + "-" + dt2[1] + "-" + dt2[0]; System.out.println("date=" + orDate); sql += " date BETWEEN '" + orDate + "' AND '" + orDate2 + "'"; if (!cat.equals("") && !cat.equals(null) || !buyer.equals("") && !buyer.equals(null) || !seller.equals("") && !seller.equals(null)) { sql += " AND "; } } if (!cat.equals("") && !cat.equals(null)) { if (where.equals("")) { where += " WHERE is_purchase!='0' AND is_purchase!='2' AND "; sql += where; } sql += "img_id IN(SELECT images_id FROM images WHERE categories_category_id='" + cat + "')"; if (!buyer.equals("") && !buyer.equals(null) || !seller.equals("") && !seller.equals(null)) { sql += " AND "; } } if (!buyer.equals("") && !buyer.equals(null)) { if (where.equals("")) { where += " WHERE is_purchase!='0' AND is_purchase!='2' AND "; sql += where; } sql += "cart_id IN(SELECT cart_id FROM cart WHERE user_id='" + buyer + "')"; if (!seller.equals("") && !seller.equals(null)) { sql += " AND "; } } if (!seller.equals("") && !seller.equals(null)) { if (where.equals("")) { where += " WHERE is_purchase!='0' AND is_purchase!='2' AND "; sql += where; } sql += "img_id IN(SELECT images_id FROM images WHERE user_user_id='" + seller + "')"; } sql += " ORDER BY date DESC"; System.out.println("sql:" + sql); Images im; int i = 1; Categories cc = null; Cart ct = null; User buy = null; User Seller = null; try { PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ResultSet rs = ps.executeQuery(); while (rs.next()) { JSONObject jo = new JSONObject(); jo.put("cid", rs.getInt(2)); im = idi.getImageDetail(rs.getInt(2)); jo.put("title", im.getTitle()); jo.put("credit", rs.getInt(7)); cc = cadi.getCategory(im.getCategories_category_id()); jo.put("category", cc.getCategory()); jo.put("date", rs.getDate(6)); ct = cdi.getACart(rs.getInt(5)); buy = udi.getUser(ct.getUser_id()); Seller = udi.getUser(im.getUser_user_id()); jo.put("buyer", buy.getUser_name()); jo.put("seller", Seller.getUser_name()); ja.add(jo); } out.write("json=" + ja.toJSONString()); } catch (Exception e) { e.printStackTrace(); out.write("msg=Internal server error,Please try again later."); } } } else { out.write("msg=Internal server error,Please try again later."); } } catch (Exception e) { e.printStackTrace(); out.write("msg=Internal server error,Please try again later."); } }
From source file:com.p000ison.dev.simpleclans2.exceptions.handling.ExceptionReporterTask.java
@Override @SuppressWarnings("unchecked") public void run() { if (queue.isEmpty()) { return;//w w w.ja v a 2 s . co m } JSONArray reports = new JSONArray(); ExceptionReport report; int i = 0; while ((report = queue.poll()) != null && i <= MAX_REPORTS_PER_PUSH) { i++; reports.add(report.getJSONObject()); } try { PHPConnection connection = new PHPConnection(PROTOCOL, HOST, PORT, FILE, true); connection.write("report=" + reports.toJSONString()); String response = connection.read(); if (response != null && !response.isEmpty()) { throw new IOException("Failed at pushing error reports: " + response); } } catch (IOException e) { Logging.debug(e, false); } }
From source file:control.ParametrizacionServlets.InsertarPuntoVertimientoContrato.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/* ww w. ja v a 2 s . 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 { try { //Obtenemos el numero de contrato Double contrato = Double.parseDouble(request.getParameter("contrato")); //Obtenemos la cadena con la informacion y la convertimos en un //JSONArray String puntos = request.getParameter("puntos"); Object obj = JSONValue.parse(puntos); JSONArray jsonArray = new JSONArray(); jsonArray = (JSONArray) obj; //Recorremos el JSONArray y obtenemos la informacion. for (int i = 0; i < jsonArray.size(); i++) { JSONObject jsonObject = (JSONObject) jsonArray.get(i); String ubicacion = (String) jsonObject.get("ubicacion"); String latitud = (String) jsonObject.get("latitud"); String longitud = (String) jsonObject.get("longitud"); String observacion = (String) jsonObject.get("observacion"); String tipoEstructura = (String) jsonObject.get("tipoEstructura"); int estado = Integer.parseInt((String) jsonObject.get("estado")); //Creamos el manager y guardamos la informacion. PuntosVertimiento manager = new PuntosVertimiento(); manager.insertar(ubicacion, latitud, longitud, observacion, estado, contrato, tipoEstructura); } } catch (Exception ex) { //Logger.getLogger(InsertarActEconomica.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:modelo.ParametrizacionManagers.AcreditacionParametros.java
/** * * Arma el la cadena JSON que seria enviada a la vista. * * @param rset//from www . j av a 2s.c o m * @return String * @throws SQLException */ private JSONObject obtenerJSONString(ResultSet rset) throws SQLException { //Variables necesarias boolean flag = false; String contrato = null; JSONArray jsonArray1 = new JSONArray(); JSONObject jsonObject1 = new JSONObject(); //Recorremos los registros obtenidos de la consulta while (rset.next()) { //Si la bandera es false, armamos la cabecera. if (!flag) { contrato = rset.getString("FK_CONTRATO"); jsonObject1.put("contrato", contrato); flag = true; } String ubicacion = rset.getString("DESCRIPCION"); String latitud = rset.getString("LATITUD"); String longitud = rset.getString("LONGITUD"); String estado = rset.getString("FK_ESTADO"); String observacion = rset.getString("OBSERVACION"); String codigo = rset.getString("CODIGO"); JSONObject jsonObject2 = new JSONObject(); jsonObject2.put("ubicacion", ubicacion); jsonObject2.put("latitud", latitud); jsonObject2.put("longitud", longitud); jsonObject2.put("observacion", observacion); jsonObject2.put("estado", estado); jsonObject2.put("codigo", codigo); jsonArray1.add(jsonObject2); } jsonObject1.put("puntos", jsonArray1); return jsonObject1; }