List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:com.aerothai.database.unit.UnitService.java
public JSONObject GetUnitAt(int id) throws Exception { Connection dbConn = null;/*from www. j ava2 s . c o 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 unit where idunit = " + id; System.out.println(query); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { JSONObject jsonData = new JSONObject(); jsonData.put("id", rs.getInt("idunit")); jsonData.put("name", rs.getString("name")); jsonData.put("shortname", rs.getString("shortname")); jsonData.put("action", rs.getString("action")); jsonData.put("addjob", rs.getString("addjob")); jsonData.put("filename", rs.getString("filename")); jsonData.put("menu", rs.getString("menu")); 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:workspace.java
private void importlast(PrintWriter out, String class1, String hour) throws Exception { String[] students = util.getStudents(class1); String[] pa = util.getpa(class1, hour); JSONArray ja = new JSONArray(), ja1 = new JSONArray(); JSONObject mainObj = new JSONObject(); ja = getJsonArrayFromStringArray(students, pa); mainObj.put("students", ja); StringWriter out1 = new StringWriter(); mainObj.writeJSONString(out1);//w w w. j a va 2 s . com String jsonText = out1.toString(); out.println(jsonText); }
From source file:com.saludtec.web.DiagnosticosWeb.java
private JSONArray guardarEvolucionComentario(HttpServletRequest request) { Diagnosticos diagnostico = new Diagnosticos(); Pacientes paciente = ejbPacientes.traer(Integer.parseInt(request.getParameter("idPaciente"))); diagnostico.setIdPaciente(paciente); diagnostico.setNombreModulo(request.getParameter("nombreModulo")); diagnostico.setNombreDiagnostico(request.getParameter("nombreDiagnostico")); diagnostico.setDiagnostico(request.getParameter("diagnostico")); diagnostico.setFecha(request.getParameter("fecha")); diagnostico.setHora(request.getParameter("hora")); diagnostico.setIdUsuario(Integer.parseInt(request.getSession().getAttribute("usuario").toString()));//RECORDAR QUE ESTE VALOR ESTA QUEMADO Y HAY QUE CAMBIARLO CUANDO SE CREE LA TABLA USUARIOS diagnostico = ejbEvolucionComentario.crear(diagnostico); obj = new JSONObject(); objArray = new JSONArray(); if (diagnostico != null) { obj.put("idDiagnostico", diagnostico.getIdDiagnostico()); objArray.add(obj);/*from w w w . ja v a2s .c om*/ } else { obj.put("error", "no se pudo guardar el diangnostico"); objArray.add(obj); } return objArray; }
From source file:control.ParametrizacionServlets.InsertarLaboratorios.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from www . j av a 2s. 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 { 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"); String paramAcreditados = request.getParameter("paramAcreditados"); Laboratorios manager = new Laboratorios(); manager.insertar(nombre, contactos, direccion, telefono, telefono2, correo, resolucion, vigencia); AcreditacionParametros managerAcreditacion = new AcreditacionParametros(); int codigoLaboratorio = manager.getCodigoLaboratorio(); // la informacion se converte en unJSONArray 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, codigoLaboratorio); } } catch (Exception e) { //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); salida.put("error", 0); response.getWriter().write(salida.toString()); } }
From source file:com.saludtec.web.EstratoSocialWeb.java
private JSONArray listarEstratos() throws NonexistentEntityException { List<EstratoSocial> estratoSociales = ejb.traerEstratoSocial(); objArray = new JSONArray(); for (EstratoSocial estratoSocial : estratoSociales) { obj = new JSONObject(); obj.put("idEstrato", estratoSocial.getIdEstrato()); obj.put("estratoSocial", estratoSocial.getEstratoSocial()); objArray.add(obj);/* w w w . ja va 2 s .c om*/ } return objArray; }
From source file:com.ibm.stocator.fs.swift.auth.PasswordScopeAccessProvider.java
/** * Authentication logic//from w w w .j a v a 2 s. c o m * * @return Access JOSS access object * @throws IOException if failed to parse the response */ public Access passwordScopeAuth() throws IOException { InputStreamReader reader = null; BufferedReader bufReader = null; try { JSONObject user = new JSONObject(); user.put("id", mUserId); user.put("password", mPassword); JSONObject password = new JSONObject(); password.put("user", user); JSONArray methods = new JSONArray(); methods.add("password"); JSONObject identity = new JSONObject(); identity.put("methods", methods); identity.put("password", password); JSONObject project = new JSONObject(); project.put("id", mProjectId); JSONObject scope = new JSONObject(); scope.put("project", project); JSONObject auth = new JSONObject(); auth.put("identity", identity); auth.put("scope", scope); JSONObject requestBody = new JSONObject(); requestBody.put("auth", auth); HttpURLConnection connection = (HttpURLConnection) new URL(mAuthUrl).openConnection(); connection.setDoOutput(true); connection.setRequestProperty("Accept", "application/json"); connection.setRequestProperty("Content-Type", "application/json"); OutputStream output = connection.getOutputStream(); output.write(requestBody.toString().getBytes()); int status = connection.getResponseCode(); if (status != 201) { return null; } reader = new InputStreamReader(connection.getInputStream()); bufReader = new BufferedReader(reader); String res = bufReader.readLine(); JSONParser parser = new JSONParser(); JSONObject jsonResponse = (JSONObject) parser.parse(res); String token = connection.getHeaderField("X-Subject-Token"); PasswordScopeAccess access = new PasswordScopeAccess(jsonResponse, token, mPrefferedRegion); bufReader.close(); reader.close(); connection.disconnect(); return access; } catch (Exception e) { if (bufReader != null) { bufReader.close(); } if (reader != null) { reader.close(); } throw new IOException(e); } }
From source file:com.swiftcorp.portal.mailinfo.web.MailinfoDispatchAction.java
public ActionForward initialLoad(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { JSONArray arr2 = new JSONArray(); JSONArray arr3 = new JSONArray(); JSONArray arr4 = new JSONArray(); JSONObject mailObj_group = new JSONObject(); JSONObject mailObj = new JSONObject(); JSONArray mail_dtl = new JSONArray(); JSONObject mails = new JSONObject(); mails.put("share_mail", mailObj); mails.put("personal_mail", mail_dtl); mails.put("company_unread", arr4); mails.put("company_all", arr3); mails.put("messages", arr3); log.info("promptMailinfoSearchSystemLevel() : enter"); try {/*from w w w . j av a 2s . c om*/ MailinfoSearchUtils.prepareSearchPage(request); String searchSqlQuery = MailinfoSearchUtils.prepareSqlQuery(request); SearchUtil.prepareRequest(request); SearchOperationResult searchOperationResult = mailinfoService.search(searchSqlQuery); log.info("searchMailinfoFromSystemLevel():: searchOperationResult> size = " + searchOperationResult.getTotalRowCount()); request.setAttribute(SESSION_KEYS.MAILINFO_SEARCH_RESULT, searchOperationResult); request.setAttribute(SESSION_KEYS.MAILINFO_INITIAL_LOAD, mails); request.setAttribute(SESSION_KEYS.IS_SEARCH_RESULT_SHOW, true); MailinfoSearchUtils.prepareSearchPage(request); } catch (Exception e) { log.info("promptMailinfoSearchSystemLevel() :", e); throw e; } // show the mailinfo search page return mapping.findForward(ForwardNames.MAILINFO_INITIAL_LOAD); }
From source file:com.product.Product.java
@GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON)//from ww w . j a v a 2 s .c o 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:com.saludtec.web.ProcedimientosWeb.java
private JSONArray traerProcedimiento(HttpServletRequest request) throws NonexistentEntityException { Procedimientos procedimiento = ejb//from ww w . j av a2 s .co m .traerProcedimientos(Integer.parseInt(request.getParameter("idProcedimiento"))); obj = new JSONObject(); objArray = new JSONArray(); if (procedimiento != null) { obj.put("idProcedimiento", procedimiento.getIdProcedimiento()); obj.put("nombreProcedimiento", procedimiento.getNombreProcedimiento()); obj.put("idCategoriaProcedimiento", procedimiento.getIdCategoriaProcedimiento().getIdCategoria()); obj.put("rangoProcedimiento", procedimiento.getRangoProcedimiento()); obj.put("cups", procedimiento.getCups()); obj.put("valor", procedimiento.getValor()); obj.put("ambitoRealizacion", procedimiento.getAmbitoRealizacion()); obj.put("finalidad", procedimiento.getFinalidad()); obj.put("actoQuirurjico", procedimiento.getActoQuirurjico()); objArray.add(obj); } return objArray; }
From source file:com.assignment4.products.Pro_details.java
@GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON)/*from ww w . j a va2s.c o m*/ 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; } }