List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:control.ParametrizacionServlets.ActualizarAsociacionContratos.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*w w w. 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 { //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")); String codigo = (String) jsonObject.get("codigo"); //Creamos el manager y guardamos la informacion. AsociacionContratos manager = new AsociacionContratos(); int error = manager.actualizar(contratoPadre, contratoHijo, codigo); /* 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:com.mobicage.rogerthat.form.MultiSelect.java
@Override @SuppressWarnings("unchecked") public JSONObject toJSONObject() { JSONObject result = super.toJSONObject(); JSONArray valuesArray = new JSONArray(); valuesArray.addAll(values);/*from w ww. jav a 2s .com*/ result.put("values", valuesArray); return result; }
From source file:assignment.HTTPResponse.java
public void serve(HTTPRequest httpRequest, OutputStream outputStream, Socket socket) throws IOException, ParseException, InterruptedException { PrintWriter pw = new PrintWriter(outputStream, true); JSONObject obj = new JSONObject(); if (httpRequest.getHttpMethod().equals("GET")) { String[] url = (httpRequest.getResourceURI()).split("\\?"); if (url[0].equals("/request")) { String ar1[] = url[1].split("&"); String[] name1 = ar1[0].split("="); String connId = name1[1]; String[] name2 = ar1[1].split("="); int timeout = Integer.parseInt(name2[1]); input[i][0] = connId;// ww w. ja v a 2s .c o m Date startTime = new Date(); Date parsedDate = df.parse(startTime.toString()); Date endTime = new Date(parsedDate.getTime() + (1 * timeout)); input[i][1] = startTime.toString(); input[i][2] = endTime.toString(); i++; obj.put("status", "ok"); try { Thread.currentThread().sleep(timeout); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } pw.println(obj); } else if (url[0].equals("/serverStatus")) { Date now = new Date(); long newDateTime = df.parse((new Date()).toString()).getTime(); String result = ""; JSONArray ja = new JSONArray(); for (int j = 0; j < input.length; j++) { if (input[j][0] != null) { Date end = df.parse(input[j][2]); if (end.compareTo(now) > 0) { long endDateTime = (df.parse(input[j][2])).getTime(); long diff = ((endDateTime - newDateTime) / 1000); JSONObject obj1 = new JSONObject(); obj1.put(input[j][0], diff); result += obj1; } } } pw.println(result); } else { pw.println("Request not supported."); } } else if ((httpRequest.getHttpMethod().equals("PUT")) || (httpRequest.getHttpMethod().equals("POST"))) { if (httpRequest.getResourceURI().equals("/kill")) { boolean found = false; Date now = new Date(); for (int j = 0; j < input.length; j++) { if (input[j][0] != null && input[j][0].equals(httpRequest.getBody())) { Date end = df.parse(input[j][2]); if (end.compareTo(now) > 0) { input[j][2] = now.toString(); found = true; } } } if (found) { obj.put("status", "killed"); } else { obj.put("status", "Invalid connId " + httpRequest.getBody()); } System.out.println(obj); pw.println(obj); } else { pw.println("Request not supported."); } } socket.close(); }
From source file:com.aerothai.database.position.PositionService.java
public JSONObject GetPositionAt(int id) throws Exception { Connection dbConn = null;//from w w w . j a va 2 s. com JSONObject obj = new JSONObject(); JSONArray objList = new JSONArray(); int no = 1; obj.put("tag", "listat"); obj.put("msg", "error"); obj.put("status", false); try { dbConn = DBConnection.createConnection(); Statement stmt = dbConn.createStatement(); String query = "SELECT * FROM position where idposition = " + id; System.out.println(query); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { JSONObject jsonData = new JSONObject(); jsonData.put("id", rs.getInt("idposition")); jsonData.put("name", rs.getString("name")); 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:com.aerothai.database.role.RoleService.java
public JSONObject GetRoleAt(int id) throws Exception { Connection dbConn = null;/* w w w . j ava 2 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 role where idrole = " + id; System.out.println(query); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { JSONObject jsonData = new JSONObject(); jsonData.put("id", rs.getInt("idrole")); jsonData.put("name", rs.getString("name")); 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:com.mobicage.rogerthat.form.AutoComplete.java
@Override @SuppressWarnings("unchecked") public JSONObject toJSONObject() { JSONObject result = super.toJSONObject(); final JSONArray suggestionArray = new JSONArray(); suggestionArray.addAll(suggestions); result.put("suggestions", suggestionArray); return result; }
From source file:is.brendan.WarpMarkers.WarpMarkersWarpInfo.java
public JSONArray load() { JSONArray jsonList = new JSONArray(); final List<String> warpNameList = new ArrayList<String>(warps.getWarpNames()); final Iterator<String> iterator = warpNameList.iterator(); while (iterator.hasNext()) { String warpName = iterator.next(); jsonList.add(getWarp(warpName)); }/*from w w w . j a v a 2 s . com*/ return jsonList; }
From source file:control.ProcesoVertimientosServlets.GenerarExcelVisitasAdmon.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w w w .ja v a 2s.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 { String fechaInicio = request.getParameter("fechaInicio"); String fechaFin = request.getParameter("fechaFin"); String tipoVisita = request.getParameter("tipoVisita"); String codigoProceso = request.getParameter("codigoProceso"); String estadoVisita = request.getParameter("estadoVisita"); String contrato = request.getParameter("contrato"); String nit = request.getParameter("nit"); String razonSocial = request.getParameter("razonSocial"); String programacion = request.getParameter("programacion"); String comuna = request.getParameter("comuna"); String direccion = request.getParameter("direccion"); JSONArray jsonArray = new JSONArray(); String filaInicio = ""; String filaFin = ""; Visitas manager = new Visitas(); String appDir = getServletContext().getRealPath("/"); appDir += "sources/VisitasPendientes.xls"; //Llamamos al manager para escribir el excel manager.escribirExcelPendientes(filaInicio, filaFin, codigoProceso, appDir, contrato, nit, razonSocial, comuna, direccion); } catch (SQLException ex) { //Logger.getLogger(GenerarExcelVisitas.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:c3.ops.priam.backup.MetaData.java
@SuppressWarnings("unchecked") public void set(List<AbstractBackupPath> bps, String snapshotName) throws Exception { File metafile = createTmpMetaFile(); FileWriter fr = new FileWriter(metafile); try {/*from w w w . j a va 2 s . c o m*/ JSONArray jsonObj = new JSONArray(); for (AbstractBackupPath filePath : bps) jsonObj.add(filePath.getRemotePath()); fr.write(jsonObj.toJSONString()); } finally { IOUtils.closeQuietly(fr); } AbstractBackupPath backupfile = pathFactory.get(); backupfile.parseLocal(metafile, BackupFileType.META); backupfile.time = backupfile.parseDate(snapshotName); try { upload(backupfile); addToRemotePath(backupfile.getRemotePath()); if (metaRemotePaths.size() > 0) { notifyObservers(); } } finally { FileUtils.deleteQuietly(metafile); } }
From source file:com.starr.smartbuilds.service.BuildService.java
public String buildData(Build build, List<Block> blocks) { JSONObject json_build = new JSONObject(); json_build.put("title", build.getName()); json_build.put("type", "custom"); json_build.put("map", "SR"); json_build.put("mode", "any"); json_build.put("type", "custom"); JSONArray json_blocks = new JSONArray(); for (Block block : blocks) { JSONObject json_block = new JSONObject(); json_block.put("type", block.getName()); JSONArray json_items = new JSONArray(); for (Item item : block.getItems()) { JSONObject json_item = new JSONObject(); json_item.put("id", item.getId() + ""); json_item.put("count", 1); json_items.add(json_item);//from w w w.ja va2 s . co m } json_block.put("items", json_items); json_blocks.add(json_block); } json_build.put("blocks", json_blocks); return json_build.toString(); }