List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:com.piusvelte.hydra.MSSQLConnection.java
@SuppressWarnings("unchecked") @Override//from w w w.ja va 2 s .c om public JSONObject execute(String statement) { JSONObject response = new JSONObject(); JSONArray errors = new JSONArray(); Statement s = null; ResultSet rs = null; try { s = mConnection.createStatement(); rs = s.executeQuery(statement); response.put("result", getResult(rs)); } catch (SQLException e) { errors.add(e.getMessage()); } finally { if (s != null) { if (rs != null) { try { rs.close(); } catch (SQLException e) { errors.add(e.getMessage()); } } try { s.close(); } catch (SQLException e) { errors.add(e.getMessage()); } } } response.put("errors", errors); if (!response.containsKey("result")) { JSONArray rows = new JSONArray(); JSONArray rowData = new JSONArray(); rows.add(rowData); response.put("result", rows); } return response; }
From source file:com.p000ison.dev.simpleclans2.JSONFlags.java
@Override public String serialize() { if (data.isEmpty()) { return null; }/*from w w w. j av a 2s . co m*/ JSONObject json = new JSONObject(); for (Map.Entry<String, Object> entry : data.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (key == null || value == null) { continue; } if (value instanceof Collection) { Collection collection = (Collection) value; if (collection.isEmpty()) { continue; } JSONArray list = new JSONArray(); list.addAll(collection); value = list; } json.put(key, value); } return json.toJSONString(); }
From source file:com.saludtec.web.DiagnosticosWeb.java
private JSONArray listarEvolucionComentario(HttpServletRequest request) { List<Diagnosticos> diagnosticos = ejbEvolucionComentario .listar(Integer.parseInt(request.getParameter("idPaciente")), request.getParameter("fecha")); objArray = new JSONArray(); if (diagnosticos != null) { for (Diagnosticos diagnostico : diagnosticos) { obj = new JSONObject(); obj.put("idDiagnostico", diagnostico.getIdDiagnostico()); obj.put("idPaciente", diagnostico.getIdPaciente().getIdPaciente()); obj.put("nombreModulo", diagnostico.getNombreModulo()); obj.put("nombreDiagnostico", diagnostico.getNombreDiagnostico()); obj.put("diagnostico", diagnostico.getDiagnostico()); obj.put("fecha", diagnostico.getFecha()); obj.put("hora", diagnostico.getHora()); objArray.add(obj);/*www . j a v a 2 s .com*/ } } return objArray; }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java
protected static void leerMultiplesTalleres(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList<TallerEntity> talleres = new ArrayList<>(); talleres = CtrlUsuario.leerMultiplesTalleres(Integer.parseInt(request.getParameter("1")), Integer.parseInt(request.getParameter("2"))); // posicin y tamao response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); System.out.println("Talleres: " + talleres.size()); JSONArray list1 = new JSONArray(); for (TallerEntity taller : talleres) { JSONObject obj = new JSONObject(); obj.put("id", taller.getIdTaller()); obj.put("titulo", taller.getNombre()); list1.add(obj);/*from www. jav a 2 s . c o m*/ } out.print(list1); }
From source file:control.ParametrizacionServlets.EliminarAsociacionContrato.java
private void eliminarContratosAsociados(HttpServletRequest request, HttpServletResponse response) throws IOException { JSONArray respError = new JSONArray(); try {/*w w w . j a va2s . com*/ //Obtenemos los paramtros enviados int codigo = Integer.parseInt(request.getParameter("codigo")); // uno significa que no hay error //Obtenemos La informacion del manager AsociacionContratos manager = new AsociacionContratos(); //Almacenamos el error que pueda resultar respError = manager.EliminarContratoAsociado(codigo); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object jsonObject : respError) { response.getWriter().write(respError.toString()); } } catch (Exception e) { JSONObject error = new JSONObject(); error.put("error", 0); respError.add(error); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object jsonObject : respError) { response.getWriter().write(respError.toString()); } } }
From source file:modelo.ParametrizacionManagers.TiposInformeVertimientos.java
/** * * Obtiene la informacion del tipo de Informe mediante un codigo y * guarda todo en un JSONArray para entregarselo a la vista. * * @return JSONArray/*w ww. ja v a 2 s .c om*/ * @throws SQLException */ public JSONArray getTipoInforme(int codigo) throws Exception { //Ejecutamos la consulta y obtenemos el ResultSet SeleccionarTiposInformesVertimiento seleccionar = new SeleccionarTiposInformesVertimiento(); ResultSet rst = seleccionar.getTipoInforme(codigo); //Creamos los JSONArray para guardar los objetos JSON JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); while (rst.next()) { //Creamos el objecto JSON jsonObject.put("descripcion", rst.getString("DESCRIPCION")); jsonObject.put("codigo", rst.getString("CODIGO")); //Creamos el Array JSON jsonArray.add(jsonObject.clone()); } seleccionar.desconectar(); return jsonArray; }
From source file:modelo.ProcesoVertimientosManagers.ProcesoVertimientos.java
public JSONArray getProcesoVertimientos() throws Exception { SeleccionarProcesoVertimientos select = new SeleccionarProcesoVertimientos(); ResultSet rset = select.ejecutar(); //Creamos los JSONArray para guardar los objetos JSON JSONArray jsonArray = new JSONArray(); JSONArray jsonArreglo = new JSONArray(); //Recorremos el ResultSet, armamos el objeto JSON con la info y guardamos //en el JSONArray. while (rset.next()) { //Armamos el objeto JSON con la informacion del registro JSONObject jsonObject = new JSONObject(); jsonObject.put("codigoProceso", rset.getString("CODIGO")); jsonObject.put("nit", rset.getString("NIT")); jsonObject.put("razonSocial", rset.getString("RAZON_SOCIAL")); jsonObject.put("actividadEconomica", rset.getString("CIIU")); jsonObject.put("contrato", rset.getString("FK_CONTRATO")); jsonObject.put("tipoInforme", rset.getString("TIPOINFORME")); jsonObject.put("fechaProceso", rset.getString("FECHA_PROCESO")); jsonObject.put("estado", rset.getString("ESTADOP")); //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista. jsonArray.add(jsonObject.clone()); }/*from w ww . ja v a 2 s. c o m*/ jsonArreglo.add(jsonArray); //Se cierra el ResultSet select.desconectar(); return jsonArreglo; }
From source file:com.saludtec.web.EvolucionComentariosWeb.java
private JSONArray listarEvolucionComentario(HttpServletRequest request) { List<EvolucionComentarios> evolucionComentarios = ejbEvolucionComentario .listar(Integer.parseInt(request.getParameter("idPaciente")), request.getParameter("fecha")); objArray = new JSONArray(); if (evolucionComentarios != null) { for (EvolucionComentarios evolucionComentario : evolucionComentarios) { obj = new JSONObject(); obj.put("idEvolucionComentario", evolucionComentario.getIdEvolucionComentario()); obj.put("idPaciente", evolucionComentario.getIdPaciente().getIdPaciente()); obj.put("firma", evolucionComentario.getFirma()); obj.put("comentario", evolucionComentario.getComentario()); obj.put("fecha", evolucionComentario.getFecha()); obj.put("hora", evolucionComentario.getHora()); objArray.add(obj);/* www . ja va 2 s .c o m*/ } } return objArray; }
From source file:com.cloudera.hoop.fs.FSUtils.java
/** * Converts a Hadoop <code>FileStatus</code> array into a JSON array * object. It replaces the <code>SCHEME://HOST:PORT</code> of the path * with the specified URL.//w w w.j av a 2s.c om * <p/> * @param status Hadoop file status array. * @param hoopBaseUrl base URL to replace the * <code>SCHEME://HOST:PORT</code> in the file status. * @return The JSON representation of the file status array. */ @SuppressWarnings("unchecked") public static JSONArray fileStatusToJSON(FileStatus[] status, String hoopBaseUrl) { JSONArray json = new JSONArray(); if (status != null) { for (FileStatus s : status) { json.add(fileStatusToJSON(s, hoopBaseUrl)); } } return json; }
From source file:biomine.bmvis2.pipeline.EdgeLabelOperation.java
public JSONObject toJSON() { JSONObject ret = new JSONObject(); JSONArray enabled = new JSONArray(); enabled.addAll(enabledLabels);// w ww. ja v a 2 s . c o m ret.put("enabled", enabled); return ret; }