List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:geo.controller.LoadDataServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from www .j av a2 s .c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); PrintWriter out = response.getWriter(); try { ArrayList<Transaction> transactionList = TransactionDAO.getTransactionList(); JSONArray jsonArray = new JSONArray(); int index = 0; //hardcode to remove error in geocode for (int i = 0; i < transactionList.size(); i++) { if (transactionList.get(i).postalCode.equals("158744")) { continue; } jsonArray.add(index++, transactionList.get(i).getJSONObject()); } out.println(jsonArray.toJSONString()); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:gr.aueb.mipmapgui.controller.file.ActionInitialize.java
private void getSavedUserFiles(String user) { JSONArray taskFileArr = new JSONArray(); ActionCreateUserDirectory actionCreateUserDirectory = new ActionCreateUserDirectory(modello); actionCreateUserDirectory.performAction(user); ActionCleanDirectory actionCleanDirectory = new ActionCleanDirectory(modello); actionCleanDirectory.performAction(user); File tasksDir = new File(Costanti.SERVER_MAIN_FOLDER + Costanti.SERVER_FILES_FOLDER + user + "/"); String[] taskFiles = tasksDir.list(DirectoryFileFilter.INSTANCE); for (String file : taskFiles) { if (!file.equalsIgnoreCase("temp")) { taskFileArr.add(file);// w w w . jav a 2 s . c o m } } JSONObject.put("savedTasks", taskFileArr); }
From source file:net.matthewauld.racetrack.server.WrSQL.java
@SuppressWarnings("unchecked") public String getJSONClassSpecificRiders(String query, String classID) throws SQLException { connect();//from ww w . j a v a 2 s. com st = con.createStatement(); rs = st.executeQuery(query); JSONObject json = new JSONObject(); JSONArray riders = new JSONArray(); while (rs.next()) { JSONObject classJSON = new JSONObject(); classJSON.put("name", fetchRiderName(rs.getInt("id"))); classJSON.put("id", rs.getInt("id")); riders.add(classJSON); } JSONObject classInfo = new JSONObject(); classInfo.put("title", fetchClassTitle(Integer.parseInt(classID))); classInfo.put("cid", Integer.parseInt(classID)); json.put("class", classInfo); if (riders.size() == 0) { json.put("riders", null); } else { json.put("riders", riders); } return json.toJSONString(); }
From source file:fr.nantes.web.quizz.servlets.Nbmovies.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int countmovies = Sparql.countMovies(); JSONArray result = new JSONArray(); JSONObject map = new JSONObject(); map.put("count", countmovies); result.add(map);/*from w w w . jav a2 s .c o m*/ response.setContentType("application/json;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { out.println(result); } }
From source file:Manager.getAllEmployees.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* ww w . j av a 2 s. c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //json to pass back to our ajax request JSONArray jsonArray = new JSONArray(); PrintWriter printout = response.getWriter(); try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost;user=sa;password=nopw"); Statement st = con.createStatement(); String query = "SELECT * FROM [MatchesFromAbove].[dbo].[Employee] WHERE active=1"; ResultSet rs = st.executeQuery(query); while (rs.next()) { JSONObject employeeToAdd = new JSONObject(); employeeToAdd.put("ssn", rs.getString("SSN")); employeeToAdd.put("role", rs.getString("Role")); employeeToAdd.put("rate", rs.getInt("Rate")); employeeToAdd.put("startdate", rs.getDate("StartDate").toString()); jsonArray.add(employeeToAdd); } //set the content type of our response response.setContentType("application/json"); //printout prints it to our ajax call and it shows up there as data. you can use this data in the success function. printout.print(jsonArray); printout.flush(); } catch (Exception e) { printout.println("NO IDEA"); return; } }
From source file:Employee.getAllCustomers.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w.j a v a2 s. c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //json to pass back to our ajax request JSONArray jsonArray = new JSONArray(); try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost;user=sa;password=nopw"); Statement st = con.createStatement(); String query = "SELECT * FROM [MatchesFromAbove].[dbo].[Customer] WHERE active=1"; ResultSet rs = st.executeQuery(query); //loop through result set and create the json objects while (rs.next()) { JSONObject customerToAdd = new JSONObject(); customerToAdd.put("ssn", rs.getString("SSN")); customerToAdd.put("ppp", rs.getString("PPP")); customerToAdd.put("rating", rs.getInt("Rating")); customerToAdd.put("lastActiveDate", rs.getTimestamp("LastActive").toString()); //add the json object that we're passing into the json array jsonArray.add(customerToAdd); } //set the content type of our response response.setContentType("application/json"); //printout prints it to our ajax call and it shows up there as data. you can use this data in the success function. PrintWriter printout = response.getWriter(); printout.print(jsonArray); printout.flush(); con.close(); } catch (Exception e) { System.out.println(e.getMessage()); return; } }
From source file:Employee.CreateMailingList.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * * @param request servlet request//from ww w. j a v a 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 */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); JSONArray jsonArray = new JSONArray(); try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost;user=sa;password=nopw"); Statement st = con.createStatement(); String query = "SELECT P.SSN, P.FirstName, P.LastName, P.Email " + "FROM [MatchesFromAbove].[dbo].[Person] P, [MatchesFromAbove].[dbo].[Customer] C" + " WHERE C.Active = 'true' AND P.SSN = C.SSN"; ResultSet rs = st.executeQuery(query); //loop through result set and create the json objects while (rs.next()) { JSONObject emailToAdd = new JSONObject(); emailToAdd.put("ssn", rs.getString("SSN")); emailToAdd.put("firstName", rs.getString("FirstName")); emailToAdd.put("lastName", rs.getString("LastName")); emailToAdd.put("email", rs.getString("Email")); //add the json object that we're passing into the json array jsonArray.add(emailToAdd); } //set the content type of our response response.setContentType("application/json"); //printout prints it to our ajax call and it shows up there as data. you can use this data in the success function. PrintWriter printout = response.getWriter(); printout.print(jsonArray); printout.flush(); } catch (Exception e) { System.out.println(e.getMessage()); return; } }
From source file:com.shazam.dataengineering.pipelinebuilder.DeploymentLog.java
public DeploymentLog() { log = new JSONObject(); log.put(ROOT, new JSONArray()); }
From source file:com.rackspacecloud.blueflood.outputs.serializers.BatchedMetricsJSONOutputSerializer.java
@Override public JSONObject transformRollupData(Map<Locator, MetricData> metricData, Set<MetricStat> filterStats) throws SerializationException { final JSONObject globalJSON = new JSONObject(); final JSONArray metricsArray = new JSONArray(); for (Map.Entry<Locator, MetricData> one : metricData.entrySet()) { final JSONObject singleMetricJSON = new JSONObject(); singleMetricJSON.put("metric", one.getKey().getMetricName()); singleMetricJSON.put("unit", one.getValue().getUnit() == null ? Util.UNKNOWN : one.getValue().getUnit()); singleMetricJSON.put("type", one.getValue().getType()); Set<MetricStat> oneFilterStats = fixFilterStats(one.getValue(), filterStats); JSONArray values = transformDataToJSONArray(one.getValue(), oneFilterStats); singleMetricJSON.put("data", values); metricsArray.add(singleMetricJSON); }// ww w . j a v a 2s . c om globalJSON.put("metrics", metricsArray); return globalJSON; }
From source file:fr.nantes.web.quizz.servlets.Addadmin.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String idadmin = request.getParameter("idadmin"); JSONArray result = new JSONArray(); JSONObject map = new JSONObject(); if (idadmin.length() == 21 && Requetesdatastore.addadmin(idadmin) == idadmin) { map.put("idadmin", idadmin); result.add(map);/*from w w w. jav a 2 s . co m*/ } else { map.put("idadmin", -100); result.add(map); } response.setContentType("application/json;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { out.println(result); } }