List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:modelo.ParametrizacionManagers.TiemposBackup.java
/** * //ww w . j a v a2 s . c o m * Obtiene la informacion de una unidad de medida y * guarda todo en un JSONArray para entregarselo a la vista. * * @return JSONArray * @throws SQLException */ public JSONArray getTiempoBackup(int codigo) throws SQLException { //Ejecutamos la consulta y obtenemos el ResultSet SeleccionarTiemposBackup select = new SeleccionarTiemposBackup(); ResultSet rset = select.getTiempoBackup(codigo); //Creamos los JSONArray para guardar los objetos JSON JSONArray jsonArray = new JSONArray(); //Recorremos el ResultSet, armamos el objeto JSON con la info y guardamos //en el JSONArray. while (rset.next()) { JSONObject jsonObject = new JSONObject(); //Armamos el objeto JSON con la informacion del registro jsonObject.put("codigo", rset.getString("CODIGO")); jsonObject.put("tiempo", rset.getString("DIAS_BACKUP")); //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista. jsonArray.add(jsonObject.clone()); } select.desconectar(); return jsonArray; }
From source file:com.product.ProductResource.java
/** * Retrieves representation of an instance of com.oracle.products.ProductResource * @return an instance of java.lang.String *//*from w w w . j a va 2 s . c om*/ @GET @Produces(MediaType.APPLICATION_JSON) public String getAllProducts() throws SQLException { if (conn == null) { return "not connected"; } else { String query = "Select * from product"; PreparedStatement pstmt = conn.prepareStatement(query); ResultSet rs = pstmt.executeQuery(); String result = ""; JSONArray productArr = new JSONArray(); while (rs.next()) { JsonObjectBuilder prodMap = Json.createObjectBuilder(); prodMap.add("productID", rs.getInt("product_id")); prodMap.add("name", rs.getString("name")); prodMap.add("description", rs.getString("description")); prodMap.add("quantity", rs.getInt("quantity")); productArr.add(prodMap); } result = productArr.toString(); return result.replace("},", "},\n"); } }
From source file:de.mpg.imeji.presentation.servlet.autocompleter.java
/** * Parse a CoNE Vocabulary (read the title value) * //from w w w . j a va 2s . com * @param cone * @return * @throws IOException */ @SuppressWarnings("unchecked") private String parseConeVocabulary(String cone) throws IOException { Object obj = JSONValue.parse(cone); JSONArray array = (JSONArray) obj; JSONArray result = new JSONArray(); for (int i = 0; i < array.size(); ++i) { JSONObject parseObject = (JSONObject) array.get(i); JSONObject sendObject = new JSONObject(); sendObject.put("label", parseObject.get("http_purl_org_dc_elements_1_1_title")); sendObject.put("value", parseObject.get("http_purl_org_dc_elements_1_1_title")); result.add(sendObject); } StringWriter out = new StringWriter(); result.writeJSONString(out); return out.toString(); }
From source file:com.oracle.products.ProductResource.java
/** * Retrieves representation of an instance of com.oracle.products.ProductResource * @return an instance of java.lang.String *//*from w ww. j av a2s .c o m*/ @GET @Produces(MediaType.APPLICATION_JSON) public String getAllProducts() throws SQLException { if (conn == null) { return "not connected"; } else { String query = "Select * from product"; PreparedStatement pstmt = conn.prepareStatement(query); 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.replace("},", "},\n"); } }
From source file:com.products.ProductResource.java
@GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON)// w w w. j a v a 2s. 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:modelo.ProcesoVertimientosManagers.InformeProcesoSeco.java
public JSONArray getArchivosCargados(int codigoProceso, Integer codigo) throws SQLException { ResultSet rset;/*from w w w . ja v a2 s . c o m*/ JSONObject jsonObject = new JSONObject(); JSONArray jsonArray = new JSONArray(); JSONArray jsonArreglo = new JSONArray(); SeleccionarArchivosInformesCargados select = new SeleccionarArchivosInformesCargados(); rset = select.getArchivosCargados(codigoProceso, codigo); while (rset.next()) { jsonObject.put("codigo", rset.getString("CODIGO")); jsonObject.put("nombreArchivo", rset.getString("NOMBRE_ARCHIVO")); jsonArray.add(jsonObject.clone()); } jsonArreglo.add(jsonArray); //Se cierra el ResultSet select.desconectar(); return jsonArreglo; }
From source file:com.oracle.products.ProductResource.java
@GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON)/*from ww w. ja v a 2 s .com*/ public String getproduct(@PathParam("id") int id) throws SQLException { if (conn == null) { return "not connected"; } else { String query = "Select * from product where product_id = ?"; PreparedStatement pstmt = conn.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:hoot.services.controllers.job.ExportJobResource.java
/** * <NAME>Export Service Get Translation Scripts List For Export</NAME> * <DESCRIPTION>//from w ww. j a va 2s. c o m * Based on the existence of translation script extension, it will send the list of available translations script for export. * </DESCRIPTION> * <PARAMETERS> * </PARAMETERS> * <OUTPUT> * List of translation script resources * </OUTPUT> * <EXAMPLE> * <URL>http://localhost:8080/hoot-services/job/export/resources</URL> * <REQUEST_TYPE>GET</REQUEST_TYPE> * <INPUT> * </INPUT> * <OUTPUT>[{"description":"LTDS 4.0","name":"NFDD"},{"description":"MGCP","name":"MGCP"},{"description":"UTP","name":"UTP"}]</OUTPUT> * </EXAMPLE> * @return */ @GET @Path("/resources") @Produces(MediaType.TEXT_PLAIN) public Response getExportResources() { String transExtPath = homeFolder + "/" + "/plugins-local/script/utp"; if (translationExtPath != null && translationExtPath.length() > 0) { transExtPath = translationExtPath; } JSONArray srvList = new JSONArray(); try { JSONObject o = new JSONObject(); o.put("name", "TDS"); o.put("description", "LTDS 4.0"); srvList.add(o); o = new JSONObject(); o.put("name", "MGCP"); o.put("description", "MGCP"); srvList.add(o); File f = new File(transExtPath); if (f.exists() && f.isDirectory()) { o = new JSONObject(); o.put("name", "UTP"); o.put("description", "UTP"); srvList.add(o); } } catch (Exception ex) { ResourceErrorHandler.handleError("Error retrieving exported resource list: " + ex.toString(), Status.INTERNAL_SERVER_ERROR, log); } return Response.ok(srvList.toString(), MediaType.APPLICATION_JSON).build(); }
From source file:com.ocs.indaba.controlpanel.controller.proj.NotificationController.java
private JSONObject importResultToJson(ProjectNotifImporter importer) { JSONObject root = new JSONObject(); root.put("errCount", importer.getErrorCount()); if (importer.getErrorCount() > 0) { JSONArray errorArray = new JSONArray(); List<String> errors = importer.getErrors(); for (String err : errors) { errorArray.add(err); }//from w w w. j av a 2 s. c om root.put("errors", errorArray); } List<ImpProjectNotif> notifs = importer.getNotifs(); root.put("count", (notifs == null) ? 0 : notifs.size()); return root; }
From source file:net.matthewauld.racetrack.server.WrSQL.java
@SuppressWarnings("unchecked") public String getJSONClasses(String query) throws SQLException { connect();// w ww . j a v a2 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(); }