List of usage examples for org.json.simple JSONArray toString
@Override
public String toString()
From source file:control.ParametrizacionServlets.EliminarPuntoVertimiento.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w w 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 los paramtros enviados int codigo = Integer.parseInt(request.getParameter("codigo")); JSONArray respError = new JSONArray(); // uno significa que no hay error //Obtenemos La informacion del manager PuntosVertimiento manager = new PuntosVertimiento(); //Almacenamos el error que pueda resultar respError = manager.Eliminar(codigo); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object jsonObject : respError) { response.getWriter().write(respError.toString()); } } catch (Exception e) { } }
From source file:control.ParametrizacionServlets.EliminarParamfisicoquimicos.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request// w w w . ja v a2 s . co 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 los paramtros enviados int codigo = Integer.parseInt(request.getParameter("codigo")); JSONArray respError = new JSONArray(); // uno significa que no hay error //Obtenemos La informacion del manager ParamFisicoquimicos manager = new ParamFisicoquimicos(); //Almacenamos el error que pueda resultar respError = manager.Eliminar(codigo); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object jsonObject : respError) { response.getWriter().write(respError.toString()); } } catch (Exception e) { } }
From source file:au.edu.ausstage.networks.SearchManager.java
/** * A method to take a group of collaborators and output JSON encoded text * Unchecked warnings are suppressed due to internal issues with the org.json.simple package * * @param collaborators the list of collaborators * @return the JSON encoded string *//*from w w w. ja v a 2s. com*/ @SuppressWarnings("unchecked") private String createJSONOutput(LinkedList<Collaborator> collaborators) { // assume that all sorting and ordering has already been carried out // loop through the list of collaborators and add them to the new JSON objects ListIterator iterator = collaborators.listIterator(0); // declare helper variables JSONArray list = new JSONArray(); Collaborator collaborator = null; while (iterator.hasNext()) { // get the collaborator collaborator = (Collaborator) iterator.next(); // add the Json object to the array list.add(collaborator.toJsonObject()); } // return the JSON encoded string return list.toString(); }
From source file:control.ParametrizacionServlets.EliminarLaboratorios.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/* w ww . j ava 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 { int codigo = Integer.parseInt(request.getParameter("codigo")); JSONArray respError = new JSONArray(); int resp = 0; //Obtenemos La informacion del manager AcreditacionParametros managerAcreditacion = new AcreditacionParametros(); //Eliminamos lo parametros resp = managerAcreditacion.eliminar(codigo); Laboratorios manager = new Laboratorios(); respError = manager.Eliminar(codigo); for (Object jsonObject : respError) { response.getWriter().write(respError.toString()); } } catch (Exception ex) { // Logger.getLogger(EliminarLaboratorios.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:control.ParametrizacionServlets.EliminarTiposInformeVertimientos.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w ww .j a va 2 s .co 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 los paramtros enviados int codigo = Integer.parseInt(request.getParameter("codigo")); JSONArray respError = new JSONArray(); // uno significa que no hay error //Obtenemos La informacion del manager TiposInformeVertimientos manager = new TiposInformeVertimientos(); //Almacenamos el error que pueda resultar respError = manager.Eliminar(codigo); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object jsonObject : respError) { response.getWriter().write(respError.toString()); } } catch (Exception e) { } }
From source file:control.ParametrizacionServlets.EliminarTiposPrmfisicoquimicos.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request// w w w. j av a2s .com * @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 los paramtros enviados int codigo = Integer.parseInt(request.getParameter("codigo")); JSONArray respError = new JSONArray(); // uno significa que no hay error //Obtenemos La informacion del manager TiposPrmfisicoquimicos manager = new TiposPrmfisicoquimicos(); //Almacenamos el error que pueda resultar respError = manager.Eliminar(codigo); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object jsonObject : respError) { response.getWriter().write(respError.toString()); } } catch (Exception e) { } }
From source file:com.assignment4.products.Pro_details.java
/** * Retrieves representation of an instance of com.oracle.products.ProductResource * @return an instance of java.lang.String *///w w w .j a va 2s. c o m @GET @Produces(MediaType.APPLICATION_JSON) public String getAllProducts() throws SQLException { if (conn == null) { return "not connected"; } else { String q = "Select * from products"; PreparedStatement ps = conn.prepareStatement(q); ResultSet rs = ps.executeQuery(); String r = ""; JSONArray proArr = new JSONArray(); while (rs.next()) { Map pm = new LinkedHashMap(); pm.put("productID", rs.getInt("product_id")); pm.put("name", rs.getString("name")); pm.put("description", rs.getString("description")); pm.put("quantity", rs.getInt("quantity")); proArr.add(pm); } r = proArr.toString(); return r.replace("},", "},\n"); } }
From source file:com.assignment4.products.Pro_details.java
@GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON)// w w w . j a va 2 s . c om public String getproduct(@PathParam("id") int id) throws SQLException { if (conn == null) { return "not connected"; } else { String q = "Select * from products where product_id = ?"; PreparedStatement ps = conn.prepareStatement(q); ps.setInt(1, id); ResultSet rs = ps.executeQuery(); String result = ""; JSONArray proArr = new JSONArray(); while (rs.next()) { Map pm = new LinkedHashMap(); pm.put("productID", rs.getInt("product_id")); pm.put("name", rs.getString("name")); pm.put("description", rs.getString("description")); pm.put("quantity", rs.getInt("quantity")); proArr.add(pm); } result = proArr.toString(); return result; } }
From source file:com.assignment.Product.java
private String getResults(String query, String... params) { String result = new String(); try (Connection conn = getConnection()) { PreparedStatement pstmt = conn.prepareStatement(query); for (int i = 1; i <= params.length; i++) { pstmt.setString(i, params[i - 1]); }// w w w . j av a 2s . c om ResultSet rs = pstmt.executeQuery(); 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); } result = productArr.toString(); } catch (SQLException ex) { Logger.getLogger(Product.class.getName()).log(Level.SEVERE, null, ex); } return result.replace("},", "},\n"); }
From source file:com.Assignment4.Prod.java
/** * Retrieves representation of an instance of com.oracle.products.ProductResource * @return an instance of java.lang.String *///from w w w . j av a 2 s . c om @GET @Produces(MediaType.APPLICATION_JSON) public String getAllProducts() throws SQLException { if (connect == null) { return "not connected"; } else { String query = "Select * from product"; PreparedStatement preparedst = connect.prepareStatement(query); ResultSet rs = preparedst.executeQuery(); String result = ""; JSONArray productArr = new JSONArray(); while (rs.next()) { Map pMap = new LinkedHashMap(); pMap.put("productID", rs.getInt("product_id")); pMap.put("name", rs.getString("name")); pMap.put("description", rs.getString("description")); pMap.put("quantity", rs.getInt("quantity")); productArr.add(pMap); } result = productArr.toString(); return result.replace("},", "},\n"); } }