List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:com.p000ison.dev.simpleclans2.exceptions.handling.ExceptionReport.java
private static Object buildThrowableJSON(Throwable thrown) { JSONArray stackTrace = new JSONArray(); for (StackTraceElement element : thrown.getStackTrace()) { stackTrace.add(element.toString()); }//w w w .j a va 2s. c o m return stackTrace; }
From source file:edu.usc.polar.NLTKRest.java
public static void ApacheNLTKRest(String doc, String args[]) { try {//from w w w . j a v a 2 s. c o m String text; AutoDetectParser parser = new AutoDetectParser(); BodyContentHandler handler = new BodyContentHandler(); Metadata metadata = new Metadata(); InputStream stream = new FileInputStream(doc); // System.out.println(stream.toString()); parser.parse(stream, handler, metadata); // return handler.toString(); text = handler.toString(); //System.out.println(text); String metaValue = metadata.toString(); System.out.println("Desc:: " + metadata.toString()); String[] example = new String[1]; example[0] = text; String name = doc.replace("C:\\Users\\Snehal\\Documents\\TREC-Data\\Data", "polar.usc.edu"); //System.out.println(text); Map<String, Set<String>> list = tikaNLTKRest(text); System.out.println(list); JSONObject jsonObj = new JSONObject(); jsonObj.put("DOI", name); jsonObj.put("metadata", metaValue.replaceAll("\\s\\s+|\n|\t", " ")); JSONArray tempArray = new JSONArray(); JSONObject tempObj = new JSONObject(); for (Map.Entry<String, Set<String>> entry : list.entrySet()) { System.out.println("\"" + entry.getKey() + "/" + ":\"" + entry.getValue() + "\""); tempObj.put(entry.getKey(), entry.getValue()); // String jsonOut="{ DOI:"+name+" ," // + ""+item.first() + "\": \"" + text.substring(item.second(), item.third()).replaceAll("\\s\\s+|\n|\t"," ")+"\"" // + "\"metadata\":\""+metaValue+"\"" // + "}"; // System.out.println(jsonOut); // tempObj.put(item.first(),text.substring(item.second(), item.third()).replaceAll("\\s\\s+|\n|\t"," ")); } tempArray.add(tempObj); jsonObj.put("NER", tempArray); jsonArray.add(jsonObj); // System.out.println("---"); } catch (Exception e) { System.out.println("ERROR : NLTKRest" + "|File Name" + doc.replaceAll("C:\\Users\\Snehal\\Documents\\TREC-Data", "") + " direct" + e.toString()); } }
From source file:com.Assignment4.Assign.java
/** * Retrieves representation of an instance of com.oracle.products.ProductResource * @return an instance of java.lang.String *//*from ww w.j av a 2 s . co m*/ @GET @Produces(MediaType.APPLICATION_JSON) public String getAllProducts() throws SQLException { if (connected == null) { return "not connected"; } else { String query = "Select * from product"; PreparedStatement ps = connected.prepareStatement(query); ResultSet rs = ps.executeQuery(); String res = ""; JSONArray productArr = new JSONArray(); while (rs.next()) { Map proMap = new LinkedHashMap(); proMap.put("productID", rs.getInt("product_id")); proMap.put("name", rs.getString("name")); proMap.put("description", rs.getString("description")); proMap.put("quantity", rs.getInt("quantity")); productArr.add(proMap); } res = productArr.toString(); return res.replace("},", "},\n"); } }
From source file:control.ParametrizacionServlets.SeleccionarAcreditacionParametros.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w w w . j a va 2 s.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 laboratorio = request.getParameter("codigo"); JSONArray jsonArray = new JSONArray(); //Obtenemos La informacion del manager AcreditacionParametros manager = new AcreditacionParametros(); jsonArray = manager.getAcreditacionPorLab(laboratorio); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object jsonObject : jsonArray) { response.getWriter().write(jsonObject.toString()); } } catch (Exception ex) { //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); response.getWriter().write(""); } }
From source file:control.ReportesServlets.EliminarHistorialDagma.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 { int codigo = Integer.parseInt(request.getParameter("codigoHistorial")); JSONArray respError = new JSONArray(); ReportesManager manager = new ReportesManager(); respError = manager.eliminarHistorialDagma(codigo); for (Object jsonObject : respError) { response.getWriter().write(respError.toString()); } } catch (Exception ex) { // Logger.getLogger(EliminarLaboratorios.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.product.ProductResource.java
/** * Retrieves representation of an instance of com.oracle.products.ProductResource * @return an instance of java.lang.String */// w ww .ja v a 2 s . com @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:es.alrocar.jpe.writer.GeoJSONWriter.java
public String write(ArrayList<JTSFeature> features) throws JSONException, BaseException { String result = null;//from w w w .j a v a 2s. co m JSONObject featureCollection = new JSONObject(); featureCollection.put("type", "featureCollection"); JSONArray featuresJSON = new JSONArray(); JSONObject featureJSON; JSONObject point; JSONObject properties; JSONArray coords; for (JTSFeature feature : features) { featureJSON = new JSONObject(); point = new JSONObject(); properties = new JSONObject(); coords = new JSONArray(); featureJSON.put("type", "Feature"); point.put("type", "Point"); coords.add(feature.getGeometry().getGeometry().getCoordinate().x); coords.add(feature.getGeometry().getGeometry().getCoordinate().y); point.put("coordinates", coords); Set keys = feature.getAttributes().keySet(); Iterator it = keys.iterator(); String key; while (it.hasNext()) { key = it.next().toString(); properties.put(key, feature.getAttribute(key).value); } featureJSON.put("geometry", point); featureJSON.put("properties", properties); featuresJSON.add(featureJSON); } featureCollection.put("features", featuresJSON); result = featureCollection.toString(); return result; }
From source file:com.imagelake.android.settings.Servlet_ImageSetting.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); try {//from ww w. j a v a 2s . com String type = request.getParameter("type"); System.out.println("type :" + type); if (type != null && !type.equals("")) { if (type.equals("SliceTypes")) { String sliceid = request.getParameter("sliceType"); if (sliceid != null && !sliceid.trim().equals("") && Integer.parseInt(sliceid) != 0) { List<SliceImage> sl = cdoi.getTypeSliceList(Integer.parseInt(sliceid), 1); if (!sl.isEmpty()) { ja = new JSONArray(); for (SliceImage sliceImage : sl) { Credits cr = cdoi.getCreditDetails(sliceImage.getCredit_id()); JSONObject jo = new JSONObject(); jo.put("cid", cr.getCredit_id()); jo.put("csize", cr.getSize()); jo.put("sid", sliceImage.getId()); ja.add(jo); } System.out.println(ja.toJSONString()); out.write("json=" + ja.toJSONString()); } else { out.write("msg=No item found."); } } else { String li = ""; out.write(li); } } else if (type.equals("allimageSlices")) { String k = cdoi.getFullSliceDetails(); System.out.println("KKKKK" + k); response.getWriter().write(k); } else if (type.equals("addsliceimage")) { String sliceid = request.getParameter("creditId"); String sliceType = request.getParameter("sliceType"); System.out.println(sliceid); System.out.println(sliceType); if (sliceid != null && !sliceid.trim().equals("") && Integer.parseInt(sliceid) != 0 && sliceType != null && !sliceType.trim().equals("") && Integer.parseInt(sliceType) != 0) { boolean ok = cdoi.insertSliceImage(Integer.parseInt(sliceid), Integer.parseInt(sliceType), 1); if (ok) { out.write("msg=Add_Slice_Successful..."); } else { out.write("msg=Unable to complete the action."); } } else { out.write("msg=Internal server error,Please try again later."); } } else if (type.equals("removesliceimage")) { String sliceid = request.getParameter("sliceId"); if (sliceid != null && !sliceid.trim().equals("") && Integer.parseInt(sliceid) != 0) { boolean ok = cdoi.removeSliceImage(Integer.parseInt(sliceid)); if (ok) { out.write("msg=Remove_Slice_Successful..."); } else { out.write("msg=Unable to complete the action."); } } else { out.write("msg=Internal server error,Please try again later."); } } else if (type.equals("AllCategories")) { List<Categories> li = new CategoriesDAOImp().listAllCategories(); ja = new JSONArray(); for (Categories categories : li) { JSONObject jo = new JSONObject(); jo.put("id", categories.getCategory_id()); jo.put("cat", categories.getCategory()); ja.add(jo); } out.write("json=" + ja.toJSONString()); } else if (type.equals("newCategories")) { String category = request.getParameter("category"); System.out.println("categ: " + category); if (category != null && !category.trim().equals("")) { boolean ok = new CategoriesDAOImp().insertCategory(category); if (ok) { out.write("msg=Add_Category_Successful..."); } else { out.write("msg=Unable to complete the action."); } } else { out.write("msg=Internal server error,Please try again later."); } } } else { out.write("msg=Internal server error,Please try again later."); } } catch (Exception e) { e.printStackTrace(); } }
From source file:modelo.ProcesoVertimientosManagers.Visitas.java
public JSONArray getVisitasPorProceso(String filaInicio, String filaFin, String tipoVisita, String fechaInicial, String fechaFinal, String codigoProceso, String estadoVisita, String contrato, String nit, String razonSocial, String motivoVisita) throws SQLException { JSONArray jsonArray = new JSONArray(); JSONArray jsonArreglo = new JSONArray(); JSONObject jsonObject = new JSONObject(); ResultSet rset;//from ww w.ja v a2 s. co m SeleccionarVisitas select = new SeleccionarVisitas(filaInicio, filaFin, tipoVisita, fechaInicial, fechaFinal, codigoProceso, estadoVisita, contrato, nit, razonSocial, motivoVisita); rset = select.getVisitas(); while (rset.next()) { jsonObject.put("codigo", rset.getString("CODIGO")); jsonObject.put("nombre", rset.getString("NOMBRES")); jsonObject.put("apellidos", rset.getString("APELLIDOS")); jsonObject.put("fecha_visita", rset.getString("FECHA_VISITA")); jsonObject.put("motivo", rset.getString("MOVITO")); jsonObject.put("tipovisita", rset.getString("TIPOVISITA")); jsonObject.put("estado", rset.getString("ESTADO")); jsonObject.put("total", rset.getString("total_rows")); jsonObject.put("resultado", rset.getString("Resultado")); jsonObject.put("contrato", rset.getString("CONTRATO")); jsonObject.put("razon_social", rset.getString("RAZON_SOCIAL")); jsonObject.put("codigoProceso", rset.getString("CODPROCESO")); jsonObject.put("tecnicoVisito", rset.getString("TECNICO_VISITO")); jsonArray.add(jsonObject.clone()); } jsonArreglo.add(jsonArray); //Se cierra el ResultSet select.desconectar(); return jsonArreglo; }
From source file:org.uom.fit.level2.datavis.controllers.chatController.ChatController.java
@RequestMapping(value = "/allmessage", method = RequestMethod.GET) public JSONArray AllMessage() { JSONArray message = new JSONArray(); JSONArray messagelength = chatServices.getAllChatDataAllMessage(); for (int i = 0; i < messagelength.toArray().length; i++) { message.add(chatServices.getAllChatData(messagelength.get(i).toString())); }/*from ww w . jav a2 s.c om*/ return message; }