List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:com.saludtec.web.EvolucionComentariosWeb.java
private JSONArray guardarEvolucionComentario(HttpServletRequest request) { EvolucionComentarios evolucionComentario = new EvolucionComentarios(); Pacientes paciente = ejbPacientes.traer(Integer.parseInt(request.getParameter("idPaciente"))); evolucionComentario.setIdPaciente(paciente); evolucionComentario.setFirma(request.getParameter("firma")); evolucionComentario.setComentario(request.getParameter("comentario")); evolucionComentario.setFecha(request.getParameter("fecha")); evolucionComentario.setHora(request.getParameter("hora")); evolucionComentario.setIdUsuario(Integer.parseInt(request.getSession().getAttribute("usuario").toString()));//RECORDAR QUE ESTE VALOR ESTA QUEMADO Y HAY QUE CAMBIARLO CUANDO SE CREE LA TABLA USUARIOS evolucionComentario = ejbEvolucionComentario.crear(evolucionComentario); obj = new JSONObject(); objArray = new JSONArray(); if (evolucionComentario != null) { obj.put("idEvolucion", evolucionComentario.getIdEvolucionComentario()); objArray.add(obj);/*from www . j av a2 s . co m*/ } else { obj.put("error", "no se pudo guardar el comentario de la evolucion"); objArray.add(obj); } return objArray; }
From source file:com.aerothai.database.radiosignal.RadiosignalService.java
public JSONObject GetRadiosignalAt(int id) throws Exception { Connection dbConn = null;//from ww w .jav a2 s.co m JSONObject obj = new JSONObject(); JSONArray objList = new JSONArray(); int no = 1; //obj.put("draw", 2); obj.put("tag", "listat"); obj.put("msg", "error"); obj.put("status", false); try { dbConn = DBConnection.createConnection(); Statement stmt = dbConn.createStatement(); String query = "SELECT * FROM radio_signal where idsignal = " + id; System.out.println(query); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { JSONObject jsonData = new JSONObject(); jsonData.put("id", rs.getInt("idsignal")); jsonData.put("idjob", rs.getString("idjob")); jsonData.put("asset_no", rs.getString("asset_no")); jsonData.put("freq", rs.getString("freq")); jsonData.put("rms", rs.getString("rms")); jsonData.put("peak", rs.getString("peak")); jsonData.put("resid", rs.getString("resid")); jsonData.put("time_err", rs.getString("time_err")); jsonData.put("power_at_15", rs.getString("power_at_15")); jsonData.put("power_at_30", rs.getString("power_at_30")); jsonData.put("rec_level", rs.getString("rec_level")); jsonData.put("no", no); objList.add(jsonData); no++; } obj.put("msg", "done"); obj.put("status", true); obj.put("data", objList); } catch (SQLException sqle) { throw sqle; } catch (Exception e) { // TODO Auto-generated catch block if (dbConn != null) { dbConn.close(); } throw e; } finally { if (dbConn != null) { dbConn.close(); } } return obj; }
From source file:control.ProcesoVertimientosServlets.SeleccionarEntidadesLodos.java
private void getLodo(HttpServletRequest request, HttpServletResponse response) { try {//from ww w . jav a2s .c o m int codigo = Integer.parseInt(request.getParameter("codigo")); JSONArray jsonArray = new JSONArray(); ManejoLodos manager = new ManejoLodos(); jsonArray = manager.getLodo(codigo); //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.products.ProductResource.java
@GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON)/* w ww. j ava 2 s.c om*/ public String getproduct(@PathParam("id") int id) throws SQLException { if (co == null) { return "not connected"; } else { String query = "Select * from product where product_id = ?"; PreparedStatement pstmt = co.prepareStatement(query); pstmt.setInt(1, id); 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; } }
From source file:com.amindorost.searchalgorithms.MainSearch.java
protected Node updateNodesQueue() { JSONObject currentIteration = new JSONObject(); JSONArray queueJSONArray = new JSONArray(); JSONObject queueJSON;//w w w . j a v a2s.com for (Node node : this.nodesQueue) { queueJSON = new JSONObject(); queueJSON.put("node", node.getNodeName()); queueJSON.put("value", Math.round(node.getNodeValue())); queueJSONArray.add(queueJSON); } currentIteration.put("queue", queueJSONArray); Node toBeSpreadedNode = pickBestNode(); if (checkGoal(toBeSpreadedNode)) { return this.dst; } JSONObject spreadingNodeJSON = new JSONObject(); spreadingNodeJSON.put("name", toBeSpreadedNode.toString()); spreadingNodeJSON.put("value", toBeSpreadedNode.getNodeValue()); currentIteration.put("spreadingNode", spreadingNodeJSON); this.iterationJSONArray.add(currentIteration); List<Node> children = this.getChildren(toBeSpreadedNode); children = updateNodesCost(children); if (children.size() != 0) { //Remove The Parent Node and replace the children this.nodesQueue.remove(toBeSpreadedNode); this.nodesQueue.addAll(children); this.processedNodes.addAll(children); } else { this.nodesQueue.remove(toBeSpreadedNode); // A leaf that is not the destination } return null; }
From source file:msuresh.raftdistdb.RaftCluster.java
private static JSONArray CreatePartitionCluster(int numReplicas) throws ExecutionException, InterruptedException { JSONArray arr = new JSONArray(); JSONObject[] lis = new JSONObject[numReplicas]; List<Address> members = new ArrayList<>(); SetupServerAddress(numReplicas, lis, members, arr); CompletableFuture<Integer> future = new CompletableFuture<>(); List<CopycatServer> atomixList = new ArrayList<>(); for (Address a : members) { ServerSetup s = new ServerSetup(members, a, atomixList, future); s.start();/*from w ww. ja v a2s.co m*/ } future.get(); return arr; }
From source file:control.ParametrizacionServlets.ActualizarLaboratorios.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request// w w w .j av a2s .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 { JSONObject salida = new JSONObject(); try { String nombre = request.getParameter("nombre"); String direccion = request.getParameter("direccion"); String telefono = request.getParameter("telefono1"); String telefono2 = request.getParameter("telefono2"); String correo = request.getParameter("correo"); String resolucion = request.getParameter("resolucion"); String vigencia = request.getParameter("vigencia"); String contactos = request.getParameter("contactos"); Integer codigo = Integer.parseInt(request.getParameter("codigo")); String paramAcreditados = request.getParameter("paramAcreditados"); Laboratorios manager = new Laboratorios(); manager.actualizar(nombre, contactos, direccion, telefono, telefono2, correo, resolucion, vigencia, codigo); int resp = 0; //Obtenemos La informacion del manager AcreditacionParametros managerAcreditacion = new AcreditacionParametros(); //Eliminamos lo parametros resp = managerAcreditacion.eliminar(codigo); Object obj = JSONValue.parse(paramAcreditados); 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); int codParametro = Integer.parseInt((String) jsonObject.get("codigoParam")); managerAcreditacion.insertar(codParametro, codigo); } } catch (Exception e) { } }
From source file:net.matthewauld.racetrack.server.WrSQL.java
@SuppressWarnings("unchecked") public String getJSONClasses(String query) throws SQLException { connect();//from ww w .j a va2 s .co m st = con.createStatement(); rs = st.executeQuery(query); JSONObject json = new JSONObject(); JSONArray classes = new JSONArray(); while (rs.next()) { JSONObject classJSON = new JSONObject(); classJSON.put("id", rs.getInt("id")); classJSON.put("title", rs.getString("title")); classes.add(classJSON); } if (classes.size() == 0) { json.put("classes", null); } else { json.put("classes", classes); } return json.toJSONString(); }
From source file:com.saludtec.web.DepartamentosWeb.java
private JSONArray listarDepartamentos() throws NonexistentEntityException { List<Departamentos> departamentos = ejb.traerDepartamentos(); objArray = new JSONArray(); for (Departamentos departamento : departamentos) { obj = new JSONObject(); obj.put("idDepartamento", departamento.getIdDepartamento()); obj.put("departamento", departamento.getDepartamento()); objArray.add(obj);//from ww w. java 2s .c om } return objArray; }
From source file:admin.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w . j av a 2 s. c o m*/ * * @param request servlet request * @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 { HttpSession session = request.getSession(); response.setContentType("application/json;charset=UTF-8"); String id = ""; String nama = ""; String email = ""; String link = ""; String admin = ""; String icw = ""; try { JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); id = userAccount.get("id").toString(); nama = userAccount.get("name").toString(); email = userAccount.get("email").toString(); link = userAccount.get("link").toString(); admin = userAccount.get("admin").toString(); icw = userAccount.get("icw").toString(); } catch (Exception ex1) { } if (admin.equalsIgnoreCase("Y")) { try (PrintWriter out = response.getWriter()) { Vector dataPosisi = new Vector(); dataPosisi.addElement("Menteri"); dataPosisi.addElement("Pejabat Setingkat Menteri"); dataPosisi.addElement("Duta Besar"); JSONArray obj1 = new JSONArray(); for (int i = 0; i < dataPosisi.size(); i++) { String FilterKey = "", FilterValue = ""; String key = "posisi", keyValue = dataPosisi.get(i).toString().toLowerCase().replaceAll(" ", ""); String table = "posisi"; DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); //Filter linkFilter = new FilterPredicate(FilterKey, FilterOperator.EQUAL, FilterValue); Key AlasanStarCalonKey = KeyFactory.createKey(key, keyValue); Query query = new Query(table, AlasanStarCalonKey); PreparedQuery pq = datastore.prepare(query); JSONArray obj11 = new JSONArray(); getData(obj11, table, key, keyValue, dataPosisi.get(i).toString(), Query.SortDirection.ASCENDING); LinkedHashMap record = new LinkedHashMap(); record.put("posisi", keyValue); record.put("nama", dataPosisi.get(i).toString()); record.put("child", obj11); obj1.add(record); } out.print(JSONValue.toJSONString(obj1)); out.flush(); } } }