List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:me.m0r13.maptools.MarkerUpdateTask.java
public void writePlayers(Player[] players) { JSONArray playersJson = new JSONArray(); for (Player player : players) { JSONObject json = new JSONObject(); Location pos = player.getLocation(); World world = player.getWorld(); json.put("username", player.getName()); json.put("x", pos.getX()); json.put("y", pos.getY()); json.put("z", pos.getZ()); json.put("world", world.getName()); json.put("dimension", world.getEnvironment().toString()); json.put("health", player.getHealth()); json.put("saturation", player.getSaturation()); json.put("food", player.getFoodLevel()); Location bed = player.getBedSpawnLocation(); if (bed == null) { json.put("bed", null); } else {/*w w w . j a v a 2s. co m*/ JSONArray bedJson = new JSONArray(); bedJson.add(bed.getBlockX()); bedJson.add(bed.getBlockY()); bedJson.add(bed.getBlockZ()); json.put("bed", bedJson); } json.put("level", (float) player.getLevel() + player.getExp()); playersJson.add(json); } JSONObject json = new JSONObject(); json.put("players", playersJson); try { File file = new File(plugin.getConfig().getString("markerFile")); BufferedWriter output = new BufferedWriter(new FileWriter(file)); output.write(json.toJSONString()); output.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:control.ProcesoVertimientosServlets.ContarParametrosIncumplidos.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request//from 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 doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { String codigoProceso = request.getParameter("codigoProceso"); JSONArray jsonArray = new JSONArray(); PDFManager manager = new PDFManager(); jsonArray = manager.contarParamIncumplidos(codigoProceso); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object jsonObject : jsonArray) { response.getWriter().write(jsonObject.toString()); } } catch (Exception ex) { //Logger.getLogger(SeleccionarLodos.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:control.ProcesoVertimientosServlets.SeleccionarLodos.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request/* w w 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 doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { int codigo = Integer.parseInt(request.getParameter("codigoProceso")); JSONArray jsonArray = new JSONArray(); ManejoLodos manager = new ManejoLodos(); jsonArray = manager.getLodosInfoTec(codigo); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object jsonObject : jsonArray) { response.getWriter().write(jsonObject.toString()); } } catch (Exception ex) { //Logger.getLogger(SeleccionarLodos.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:modelo.ProcesoVertimientosManagers.InformacionTecnica.java
/** * //from w w w . ja v a2 s . co m * Arma el JSON con la informacion tecnica. * * @param codigoProceso * @return * @throws Exception */ public JSONArray getInformacionTecnica(int codigoProceso) throws Exception { int cantidadDatos = hayDatos(codigoProceso); //Mangers necesarios y Delegates Necesarios PuntosVertimiento puntoVert = new PuntosVertimiento(); ParamFisicoquimicos param = new ParamFisicoquimicos(); //Creamos el contenedor principal del JSON JSONArray contenedorPrincipal = new JSONArray(); //Obtenemos la informacion del punto de vertimiento. Object data[] = puntoVert.getPuntosParaInfoTecnica(codigoProceso); ResultSet rset1 = (ResultSet) data[0]; //Array para guardar la informacion del punto JSONArray puntoArray = new JSONArray(); int puntoMonitoreo = 0; //Guardamos la informacion del punto en el JSON while (rset1.next()) { JSONObject puntoObject = new JSONObject(); puntoObject.put("codigo", rset1.getString("PUNTO_MONITOREO")); puntoMonitoreo = Integer.parseInt(rset1.getString("PUNTO_MONITOREO")); puntoObject.put("ubicacion", rset1.getString("UBICACION")); puntoObject.put("latitud", rset1.getString("LATITUD")); puntoObject.put("longitud", rset1.getString("LONGITUD")); puntoObject.put("ciiu", rset1.getString("CIIU")); puntoObject.put("fechaMonitoreo", rset1.getString("FECHA_MONITOREO_PUNTO")); puntoObject.put("descripcionCiiu", rset1.getString("DESCRIPCION_CIIU")); puntoObject.put("jordanadaProductivaDia", rset1.getString("JPRODDIAS")); puntoObject.put("jordanadaProductivaHoras", rset1.getString("JPRODHORAS")); puntoObject.put("jordanadaProductivaObsev", rset1.getString("JPRODOBV")); int ciiu = rset1.getInt("CIIU"); //Guardamos las informacion de la jornada JSONArray arrayJornada = new JSONArray(); SeleccionarInfoTecJornadas infoTecJornadas = new SeleccionarInfoTecJornadas(); //Validamos si ya hay datos registrados en las jornadas y en los detalles de las jornadas. if (cantidadDatos > 0) { //Obtenemos La informacion de las jornadas y las guardamos en el JSON ResultSet rsetJornadas = infoTecJornadas.getJornadas(puntoMonitoreo); while (rsetJornadas.next()) { JSONObject objectJornada = new JSONObject(); objectJornada.put("nombre", "Jornada " + rsetJornadas.getInt("JORNADA")); objectJornada.put("cargaDBO", rsetJornadas.getDouble("CARGA_DBO")); objectJornada.put("cargaSST", rsetJornadas.getDouble("CARGA_SST")); objectJornada.put("horaInicio", rsetJornadas.getString("HORA_INICIO")); objectJornada.put("horaFin", rsetJornadas.getString("HORA_FIN")); objectJornada.put("caudalJornada", rsetJornadas.getString("CAUDAL_JORNADA")); int jornada = rsetJornadas.getInt("JORNADA"); //Obtenemos y guardamos la informacion de cada parametro Object data2[] = param.getParametrosParaInfoTecnica(puntoMonitoreo, jornada, ciiu); ResultSet rset2 = (ResultSet) data2[0]; JSONArray arrayParametro = new JSONArray(); while (rset2.next()) { JSONObject objectParametro = new JSONObject(); objectParametro.put("parametro", rset2.getString("PARAMETRO")); objectParametro.put("codigoParametro", rset2.getString("CODIGO_PARAMETRO")); objectParametro.put("rangoInicial", rset2.getString("RANGO_INICIAL")); objectParametro.put("rangoFinal", rset2.getString("RANGO_FINAL")); objectParametro.put("valorInforme", rset2.getDouble("VALOR")); objectParametro.put("cumple", rset2.getString("CUMPLE")); objectParametro.put("observacion", rset2.getString("OBSERVACION")); objectParametro.put("indicardorMenor", rset2.getString("MENOR")); arrayParametro.add(objectParametro); } //Cerramos conexion de parametros SeleccionarPrmfisicoquimicos select2 = (SeleccionarPrmfisicoquimicos) data2[1]; select2.desconectar(); //Guardamos los parametros en la jornada. objectJornada.put("tabla", arrayParametro); //Guardamos la Jornada arrayJornada.add(objectJornada); } //Cerramos la conexion de jornadas } else if (cantidadDatos == 0) { //Guardamos la informacion de las jornadas for (int i = 1; i < 5; i++) { JSONObject objectJornada = new JSONObject(); objectJornada.put("nombre", "Jornada " + i); objectJornada.put("cargaDBO", ""); objectJornada.put("cargaSST", ""); objectJornada.put("horaInicio", ""); objectJornada.put("horaFin", ""); objectJornada.put("caudalJornada", ""); //Obtenemos y guardamos la informacion de cada parametro Object data2[] = param.getParametrosParaInfoTecnica(ciiu); ResultSet rset2 = (ResultSet) data2[0]; JSONArray arrayParametro = new JSONArray(); while (rset2.next()) { JSONObject objectParametro = new JSONObject(); objectParametro.put("parametro", rset2.getString("PARAMETRO")); objectParametro.put("codigoParametro", rset2.getString("CODIGO_PARAMETRO")); objectParametro.put("rangoInicial", rset2.getString("RANGO_INICIAL")); objectParametro.put("rangoFinal", rset2.getString("RANGO_FINAL")); objectParametro.put("valorInforme", ""); objectParametro.put("cumple", ""); objectParametro.put("observacion", ""); objectParametro.put("indicardorMenor", ""); arrayParametro.add(objectParametro); } //Cerramos conexion de parametros SeleccionarPrmfisicoquimicos select2 = (SeleccionarPrmfisicoquimicos) data2[1]; select2.desconectar(); //Guardamos los parametros en la jornada. objectJornada.put("tabla", arrayParametro); //Guardamos la Jornada arrayJornada.add(objectJornada); } } //guardamos las jornadas en el punto puntoObject.put("jornadas", arrayJornada); puntoArray.add(puntoObject); infoTecJornadas.desconectar(); } contenedorPrincipal.add(puntoArray); //Cerrar Conexion. SeleccionarPuntosVertimiento select = (SeleccionarPuntosVertimiento) data[1]; select.desconectar(); return contenedorPrincipal; }
From source file:functionnality.LikerLineST2.java
public LineStatus rateLigne(String login, String value) { CouchDBWebRequest couchDB = new CouchDBWebRequest(); message = "Consultation"; JSONObject response;// w w w .jav a 2s .c om couchDB.addPath("/id_ligne_" + lineS.getIdentifiant()); response = couchDB.parseResultJSON(couchDB.requestWithGet()); //Requete des valeurs d'une ligne if (response.get("error") != null) { createTable(lineS.getIdentifiant()); response = couchDB.parseResultJSON(couchDB.requestWithGet()); } if (response.get("Voted") == null) { response.put("Voted", new JSONArray()); } //((JSONObject)((JSONArray)response.get("Voted")).get(0)).get("login") int i = 0; boolean trouver = false; while (i < ((JSONArray) response.get("Voted")).size() && !trouver) { if (((JSONObject) ((JSONArray) response.get("Voted")).get(i)).get("login").equals(login)) { trouver = true; } i++; } if (trouver) { message = "You have already voted"; } else { try { JSONObject jsonObj = new JSONObject(); jsonObj.put("login", new String(login.getBytes("ISO-8859-1"), Charset.forName("UTF-8"))); jsonObj.put("value", value); if (value.equals("like")) { ((JSONObject) response).put("like", (long) response.get("like") + 1); message = "You have voted like with " + login; } else { ((JSONObject) response).put("unlike", (long) response.get("unlike") + 1); message = "You have voted unlike with " + login; } ((JSONArray) response.get("Voted")).add(jsonObj); couchDB.requestWithPut(response.toString()); } catch (UnsupportedEncodingException ex) { return null; } } lineS.setLike(Integer.parseInt(("" + response.get("like")))); lineS.setUnlike(Integer.parseInt(("" + response.get("unlike")))); return lineS; }
From source file:control.ProcesoVertimientosServlets.SeleccionarResultadoVisita.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request/* ww w. j a v a2 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 doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String codigoVisita = request.getParameter("codigoVisita"); try { JSONArray jsonArray = new JSONArray(); Visitas manager = new Visitas(); jsonArray = manager.obtenerResultadoVisita(codigoVisita); //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:org.kitodo.data.elasticsearch.index.type.BaseType.java
/** * Method for adding relationship between bean objects. * /*from w w w .j av a2 s . c o m*/ * @param objects * list * @return JSONArray */ @SuppressWarnings("unchecked") <F extends BaseBean> JSONArray addObjectRelation(List<F> objects) { JSONArray jsonArray = new JSONArray(); if (objects != null) { for (F property : objects) { jsonArray.add(addIdForRelation(property.getId())); } } return jsonArray; }
From source file:ca.fastenalcompany.jsonconfig.ProductJson.java
/** * Produces a basic JSON Object using the JSON Object API * * @return - The JSON Object/*from w w w . ja v a 2 s . c o m*/ */ public JSONArray query(String query, String... params) { Connection conn = null; JSONArray products = new JSONArray(); try { conn = DBManager.getMysqlConn(); PreparedStatement pstmt = conn.prepareStatement(query); for (int i = 1; i <= params.length; i++) { pstmt.setString(i, params[i - 1]); } System.out.println(query); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { JSONObject product = new JSONObject(); for (int i = 1; i < rs.getMetaData().getColumnCount() + 1; i++) { String label = rs.getMetaData().getColumnLabel(i); String value = rs.getString(label); product.put(label, value); } products.add(product); } } catch (SQLException ex) { ex.printStackTrace(); } finally { try { System.out.println(PropertyManager.getProperty("db_conn_closed")); if (conn != null) { conn.close(); } } catch (SQLException ex) { ex.printStackTrace(); } } return products; }
From source file:mysynopsis.JSONWriter.java
public static void writeData() throws IOException { JSONObject bio = new JSONObject(); bio.put("Name", name); bio.put("Initial", initial); bio.put("Bio", biog); bio.put("Designation", designation); bio.put("Department", dept); bio.put("University", university); bio.put("University_Address", universityAddress); bio.put("Office", office); bio.put("Ohours", officehours); bio.put("Phone", phone); bio.put("Email", email); bio.put("Resume_Link", resumelink); bio.put("Educational", education); bio.put("Professional", professional); bio.put("Awards", awards); bio.put("Image_Ext", imgExtension); bio.put("Image_String", imgString); /*JSONArray education = new JSONArray(); for(int i=0;i<8;i++) {// w w w . j av a2s .c o m education.add(educ[i]); } bio.put("Education",education);*/ JSONArray ftpinfo = new JSONArray(); ftpinfo.add(server); ftpinfo.add(user); ftpinfo.add(dir); bio.put("Server_Information", ftpinfo); try (FileWriter file = new FileWriter("data.json")) { file.write(bio.toJSONString()); } catch (IOException e) { JOptionPane.showMessageDialog(null, "Can't Create Data.json File. Please Check Your Directory Permission"); } }
From source file:com.facebook.tsdb.tsdash.server.MetricsEndpoint.java
@Override @SuppressWarnings("unchecked") public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); try {//from w ww . jav a 2s .c o m TsdbDataProvider dataProvider = TsdbDataProviderFactory.get(); String[] metrics = dataProvider.getMetrics(); response.setContentType("text/plain"); JSONArray encoded = new JSONArray(); for (String metric : metrics) { encoded.add(metric); } out.println(encoded.toJSONString()); } catch (Exception e) { out.println(getErrorResponse(e)); } out.close(); }