List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:com.saludtec.web.DescripcionPlanDeTratamientoWeb.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/descripcionPlanDeTratamiento/", ""); switch (servicio) { case "guardar": guardarDescripcionPlanDeTratamiento(request).writeJSONString(out); break; case "listar": listarDescripcionPlanDeTratamiento(request).writeJSONString(out); break; default://from w w w. j ava 2 s .co m 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.appzone.sim.services.handlers.ReceiveSmsCheckServiceHandler.java
@Override protected String doProcess(HttpServletRequest request) { String address = request.getParameter(KEY_ADDRESS); String sinceStr = request.getParameter(KEY_SINCE); logger.debug("request sms messages for: {} since: {}", address, sinceStr); long since = Long.parseLong(sinceStr); List<Sms> messages = smsRepository.find(address, since); JSONArray list = new JSONArray(); for (Sms sms : messages) { JSONObject json = new JSONObject(); json.put(JSON_KEY_MESSAGE, sms.getMessage()); json.put(JSON_KEY_RECEIVED_DATE, sms.getReceivedDate()); 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:control.ParametrizacionServlets.EliminarMotivosVisitas.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/* w w w . j a v a 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 MotivosVisitas manager = new MotivosVisitas(); //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.InsertarAsociacionContratos.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//ww w . j a v a2s . 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 { objectErrores = new JSONObject(); arrayErrores = new JSONArray(); //Obtenemos el numero de contrato Double contratoPadre = Double.parseDouble(request.getParameter("contrato")); //Obtenemos la cadena con la informacion y la convertimos en un //JSONArray String puntos = request.getParameter("contratosAsignados"); 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++) { //Obtenemos el contrato hijo JSONObject jsonObject = (JSONObject) jsonArray.get(i); Double contratoHijo = Double.parseDouble((String) jsonObject.get("contratoAsignado")); //Creamos el manager y guardamos la informacion. AsociacionContratos manager = new AsociacionContratos(); int error = manager.insertar(contratoPadre, contratoHijo); /* Obtenemos la respuesta del procedimiento y Validamos si el contrato padre es valido, si no lo es no registramos nada y enviamos el error. */ if (error == 2) { guardarErrores(error, contratoPadre); escribirJSON(response); break; } else if (error == 4) { //Si el hijo no es valido, registramos el error y //enviamos el listado a la vista al finalizar el for. guardarErrores(error, contratoHijo); } } escribirJSON(response); } catch (Exception ex) { JSONObject respError = new JSONObject(); respError.put("error", 0); arrayErrores.add(respError); escribirJSON(response); } }
From source file:control.ClienteServlets.EliminarCliente.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from ww w. ja va 2 s . c om*/ * @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 ClientesManager manager = new ClientesManager(); //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.EliminarActEconomica.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request// w ww . j ava2s .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 ActividadEconomica manager = new ActividadEconomica(); //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:bookUtilities.PopulateMyBooksServlet.java
private JSONArray getUserBooks(String email, JSONArray fileTypes) { String query;/*from w w w .j a v a 2 s . co m*/ JSONArray jsons = new JSONArray(); try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost;user=sa;password=nopw"); Statement st = con.createStatement(); query = "SELECT Book.*, checkedBooks.ExpirationDate " + "FROM [HardCover].[dbo].[Book] Book, [HardCover].[dbo].[RegisteredUser] RegisteredUser, [HardCover].[dbo].[CheckedOutBook] checkedBooks, [HardCover].[dbo].[Person] P " + "WHERE Book.BookUuid = checkedBooks.BookId AND checkedBooks.RegisteredUserId = RegisteredUser.RegisteredUserId AND P.PersonUuid = RegisteredUser.RegisteredUserId " + " AND P.Email = '" + email + "' AND checkedBooks.Expired = 0"; ResultSet rs = st.executeQuery(query); /* TODO output your page here. You may use following sample code. */ while (rs.next()) { JSONObject bookToAdd = new JSONObject(); JSONArray fileTypesArray = new JSONArray(); Statement st2 = con.createStatement(); Statement st3 = con.createStatement(); Timestamp timeStamp = rs.getTimestamp("ExpirationDate"); String timeString = timeStamp.toString(); String bookId = rs.getString("BookUuid"); query = "SELECT AuthorName " + "FROM [HardCover].[dbo].[Author] " + "WHERE BookId = '" + bookId + "';"; ResultSet rs2 = st2.executeQuery(query); rs2.next(); query = "SELECT FileType, DownloadLink " + "FROM [HardCover].[dbo].[BookFileType] " + "WHERE BookId = '" + bookId + "'"; ResultSet rs3 = st3.executeQuery(query); while (rs3.next()) { JSONObject fileTypeToAdd = new JSONObject(); fileTypeToAdd.put("fileType", rs3.getString("FileType")); fileTypeToAdd.put("downloadLink", rs3.getString("DownLoadLink")); fileTypesArray.add(fileTypeToAdd); } fileTypes.add(fileTypesArray); bookToAdd.put("expirationDate", timeString); bookToAdd.put("author", rs2.getString("AuthorName")); bookToAdd.put("title", rs.getString("Title")); bookToAdd.put("cover", rs.getString("Cover")); bookToAdd.put("dateAdded", rs.getString("DateAdded")); bookToAdd.put("bookId", rs.getString("BookUuid")); jsons.add(bookToAdd); } } catch (Exception e) { System.out.println(e.getMessage()); } return jsons; }
From source file:control.ParametrizacionServlets.EliminarUnidadesMedida.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from ww w . j a va2 s . c om*/ * @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 UnidadesMedida manager = new UnidadesMedida(); //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:net.sourceforge.fenixedu.presentationTier.Action.externalServices.DomainObjectJSONSerializer.java
public static JSONObject getDomainObject(DomainObject obj) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { final JSONObject jsonObject = new JSONObject(); final Class<? extends DomainObject> clazz = obj.getClass(); final String objClassName = clazz.getName(); jsonObject.put("externalId", obj.getExternalId()); jsonObject.put("className", objClassName); final DomainClass domainClass = getDomainClass(objClassName); if (domainClass == null) { return jsonObject; }/* www. ja v a 2s .co m*/ for (Slot slot : getAllSlots(domainClass)) { final String slotName = slot.getName(); final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName)); final Object result = method.invoke(obj); jsonObject.put(slotName, result == null ? null : result.toString()); } for (Role roleSlot : getAllRoleSlots(domainClass)) { final String slotName = roleSlot.getName(); if (roleSlot.getMultiplicityUpper() == 1) { final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName)); final AbstractDomainObject singleRelationObj = (AbstractDomainObject) method.invoke(obj); final JSONArray oneRelation = new JSONArray(); if (singleRelationObj != null) { oneRelation.add(singleRelationObj.getExternalId()); } jsonObject.put(slotName, oneRelation); } else { final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName) + "Set"); final Set<? extends AbstractDomainObject> result = (Set<? extends AbstractDomainObject>) method .invoke(obj); jsonObject.put(slotName, serializeRelation(result)); } } return jsonObject; }
From source file:com.products.ProductResource.java
/** * Retrieves representation of an instance of com.oracle.products.ProductResource * @return an instance of java.lang.String *//* w w w . j a v a 2 s. c o m*/ @GET @Produces(MediaType.APPLICATION_JSON) public String getAllProducts() throws SQLException { if (co == null) { return "not connected"; } else { String query = "Select * from product"; PreparedStatement pstmt = co.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"); } }