List of usage examples for org.json.simple JSONArray get
public E get(int index)
From source file:com.intuit.tweetstest.TweetsController.java
public List<String> getFollowingList(JSONArray jsonArray) { List<String> followingList = null; int length = jsonArray.size(); if (jsonArray != null) { followingList = new ArrayList<>(); for (int i = 0; i < length; i++) { followingList.add((String) jsonArray.get(i)); }/*from ww w. j a v a2 s. co m*/ } return followingList; }
From source file:de.ingrid.iplug.dsc.utils.BwstrLocUtil.java
/** * Get the bounding box of the parsed response. * // ww w.j a va2 s . c o m * @param parsedResponse * @return The bounding box [minLon, maxLon, minLat, maxLat]. */ public Double[] getBBOX(JSONObject parsedResponse) { Double[] result = null; JSONObject re = (JSONObject) ((JSONArray) parsedResponse.get("result")).get(0); JSONArray coordinates = (JSONArray) ((JSONObject) re.get("geometry")).get("coordinates"); Double maxLon = null; Double maxLat = null; Double minLon = null; Double minLat = null; for (Object c : coordinates) { JSONArray a = (JSONArray) c; for (Object cc : a) { JSONArray aa = (JSONArray) cc; double lon = (Double) aa.get(0); double lat = (Double) aa.get(1); if (maxLon == null) maxLon = lon; if (maxLat == null) maxLat = lat; if (minLon == null) minLon = lon; if (minLat == null) minLat = lat; if (lon > maxLon) maxLon = lon; if (lon < minLon) minLon = lon; if (lat > maxLat) maxLat = lat; if (lat < minLat) minLat = lat; } } result = new Double[] { minLon, maxLon, minLat, maxLat }; return result; }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.viewer.MapperProxy.java
@Override public void run() { running = true;//from w ww . jav a 2s. c o m while (running) { List<EngineInfo> newEngineInfoList = new ArrayList<EngineInfo>(); String newZoneInfo = null; for (URI mapper : configuration.getMapperUrlList()) { if (newZoneInfo == null) { newZoneInfo = getMapperValue(mapper, "zones"); } String jsonString = getMapperValue(mapper, "mapperStatus"); if (jsonString != null && !jsonString.isEmpty()) { try { JSONArray obj = (JSONArray) parser.parse(jsonString); for (int k = 0, l = obj.size(); k < l; ++k) { JSONObject o = (JSONObject) obj.get(k); JSONObject rd = (JSONObject) o.get("regDat"); String engineUrl = (String) rd.get("engUri"); String pilotUri = (String) rd.get("pilotUri"); String pilotName = (String) rd.get("pilotName"); String positionUrl = null; String waypointsUrl = null; if (pilotUri != null && !pilotUri.isEmpty()) { positionUrl = pilotUri + "/json/position"; waypointsUrl = pilotUri + "/json/waypoints"; } String vehicleStatusUrl = engineUrl + "/json/vehicle"; String actionPointUrl = engineUrl + "/json/actionPoint"; String vehicleDataUrl = engineUrl + "/vehicle/html/vehicleData"; String temperatureUrl = engineUrl + "/json/temperature"; newEngineInfoList.add(new EngineInfo(pilotName, positionUrl, waypointsUrl, vehicleStatusUrl, actionPointUrl, vehicleDataUrl, temperatureUrl)); } } catch (ParseException e1) { LOG.error("Error at parsing JSON string '" + jsonString + "'", e1); } } } engineInfoList = newEngineInfoList; zoneInfo = newZoneInfo; try { Thread.sleep(CYCLE); } catch (InterruptedException e) { } } }
From source file:control.ProcesoVertimientosServlets.RegistrarSuperviciones.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w ww . j a v a 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 { JSONArray resp = new JSONArray(); try { //Obtenemos la cadena con la informacion y la convertimos en un //JSONArray String monitoreos = request.getParameter("monitoreos"); int tecnico = Integer.parseInt(request.getParameter("tecnico")); int resul; int codProceso; JSONObject jsonObject = new JSONObject(); JSONArray jsonArray = new JSONArray(); Object obj = JSONValue.parse(monitoreos); JSONArray monitoreosArray = new JSONArray(); monitoreosArray = (JSONArray) obj; //Recorremos el JSONArray y obtenemos la informacion. for (int i = 0; i < monitoreosArray.size(); i++) { codProceso = Integer.parseInt(monitoreosArray.get(i).toString()); ProgramarMonitoreo manager = new ProgramarMonitoreo(); resul = manager.registrarSupervision(codProceso, tecnico); jsonObject.put("monitoreo", codProceso); jsonObject.put("resultado", resul); jsonArray.add(jsonObject.clone()); } resp.add(jsonArray); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object jsonObjectResp : resp) { response.getWriter().write(jsonObjectResp.toString()); } } catch (Exception ex) { } }
From source file:control.ParametrizacionServlets.InsertarLaboratorios.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request// w ww . j av 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 doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JSONObject salida = new JSONObject(); try { String nombre = request.getParameter("nombre"); String direccion = request.getParameter("direccion"); String telefono = request.getParameter("telefono1"); String telefono2 = request.getParameter("telefono2"); String correo = request.getParameter("correo"); String resolucion = request.getParameter("resolucion"); String vigencia = request.getParameter("vigencia"); String contactos = request.getParameter("contactos"); String paramAcreditados = request.getParameter("paramAcreditados"); Laboratorios manager = new Laboratorios(); manager.insertar(nombre, contactos, direccion, telefono, telefono2, correo, resolucion, vigencia); AcreditacionParametros managerAcreditacion = new AcreditacionParametros(); int codigoLaboratorio = manager.getCodigoLaboratorio(); // la informacion se converte en unJSONArray Object obj = JSONValue.parse(paramAcreditados); JSONArray jsonArray = new JSONArray(); jsonArray = (JSONArray) obj; //Recorremos el JSONArray y obtenemos la informacion. for (int i = 0; i < jsonArray.size(); i++) { JSONObject jsonObject = (JSONObject) jsonArray.get(i); int codParametro = Integer.parseInt((String) jsonObject.get("codigoParam")); managerAcreditacion.insertar(codParametro, codigoLaboratorio); } } catch (Exception e) { //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); salida.put("error", 0); response.getWriter().write(salida.toString()); } }
From source file:gui.EventAllReader.java
@Override public void run() { RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(10 * 1000).build(); HttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build(); //HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet("https://api.guildwars2.com/v1/event_names.json?lang=" + this.language); HttpResponse response;/* w ww . ja v a 2 s.c om*/ String line = ""; String out = ""; while (!this.isInterrupted()) { try { response = client.execute(request); if (response.getStatusLine().toString().contains("200")) { BufferedReader rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent(), Charset.forName("UTF-8"))); line = ""; out = ""; while ((line = rd.readLine()) != null) { out = out + line; } JSONParser parser = new JSONParser(); Object obj; this.result.clear(); try { obj = parser.parse(out); JSONArray array = (JSONArray) obj; for (int i = 0; i < array.size(); i++) { JSONObject obj2 = (JSONObject) array.get(i); if (obj2.get("name") != null) { this.result.put(obj2.get("id"), obj2.get("name")); } } this.apimanager.updateToolTips(); request.releaseConnection(); this.interrupt(); } catch (ParseException ex) { try { Logger.getLogger(ApiManager.class.getName()).log(Level.SEVERE, null, ex); request.releaseConnection(); Thread.sleep(5000); } catch (InterruptedException ex1) { Logger.getLogger(EventAllReader.class.getName()).log(Level.SEVERE, null, ex1); } } } else { try { request.releaseConnection(); Thread.sleep(5000); } catch (InterruptedException ex) { Logger.getLogger(EventAllReader.class.getName()).log(Level.SEVERE, null, ex); } } } catch (IOException | IllegalStateException ex) { try { Logger.getLogger(EventReader.class.getName()).log(Level.SEVERE, null, ex); request.releaseConnection(); Thread.sleep(5000); } catch (InterruptedException ex1) { Logger.getLogger(EventAllReader.class.getName()).log(Level.SEVERE, null, ex1); this.interrupt(); } } } }
From source file:JavaCloud.Api.java
public ArrayList<Template> templateList() throws CoreException { JSONObject object = new JSONObject(); object.put("token", token); JSONArray jsontemplates = (JSONArray) Utils.request(address, "/api/template/get_list/", object); ArrayList<Template> templates = new ArrayList<Template>(); for (int i = 0; i < jsontemplates.size(); i++) { templates.add(new Template(address, token, (JSONObject) jsontemplates.get(i))); }//from www . j a v a 2 s. c om return templates; }
From source file:gov.nasa.jpl.xdata.nba.impoexpo.manager.NBAManager.java
@Override public void aquire(String parseType, Object input) { try {//from w w w . java 2 s . com // Read given JSON file LOG.info("Parsing file:" + input); FileReader reader = new FileReader((String) input); // Pare with JSON simple parser JSONParser jsonParser = new JSONParser(); JSONObject jsonObject = (JSONObject) jsonParser.parse(reader); JSONArray result = (JSONArray) jsonObject.get("resultSets"); JSONObject jObj = (JSONObject) result.get(0); JSONArray rows = (JSONArray) jObj.get("rowset"); String[] inputlist = input.toString().split("/"); String filename = inputlist[inputlist.length - 1]; String gameId = filename.substring(0, filename.indexOf('_')); if (parseType.equalsIgnoreCase("parseComments")) { long comments = 0; LOG.info("finished parsing file. Total number of comments:" + comments); } else if (parseType.equalsIgnoreCase("parseGamePlayers")) { long players = 0; for (int i = 0; i < rows.size(); i++) { // Store the gamePlayers with key id == gameId_playerId GamePlayer gpGamePlayer = parseGamePlayer(gameId, (JSONArray) rows.get(i)); storeGamePlayers(gpGamePlayer.getId(), gpGamePlayer); ++players; } reader.close(); LOG.info("finished parsing file. Total number of players:" + players); } else if (parseType.equalsIgnoreCase("parseGamestats")) { long stats = 0; LOG.info("finished parsing file. Total number of game stats:" + stats); } else if (parseType.equalsIgnoreCase("parseNotebook")) { long notebook = 0; LOG.info("finished parsing file. Total number of game stats:" + notebook); } else if (parseType.equalsIgnoreCase("parsePlayByPlay")) { long plays = 0; LOG.info("finished parsing file. Total number of game stats:" + plays); } else if (parseType.equalsIgnoreCase("parsePreview")) { long preview = 0; LOG.info("finished parsing file. Total number of game stats:" + preview); } else if (parseType.equalsIgnoreCase("parseRecap")) { long recaps = 0; LOG.info("finished parsing file. Total number of game stats:" + recaps); } } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } catch (ParseException ex) { ex.printStackTrace(); } catch (NullPointerException ex) { ex.printStackTrace(); } }
From source file:gui.WvWMatchReader.java
@Override public void run() { RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(10 * 1000).build(); HttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build(); //HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet("https://api.guildwars2.com/v1/wvw/matches.json"); HttpResponse response;//from w w w .ja v a2s . c o m String line = ""; String out = ""; while (!this.isInterrupted()) { try { response = client.execute(request); if ((response.getStatusLine().toString().contains("200"))) { BufferedReader rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent(), Charset.forName("UTF-8"))); line = ""; out = ""; while ((line = rd.readLine()) != null) { out = out + line; } JSONParser parser = new JSONParser(); Object obj; this.result.clear(); try { obj = parser.parse(out); JSONObject obj2 = (JSONObject) obj; JSONArray array = (JSONArray) obj2.get("wvw_matches"); for (int i = 0; i < array.size(); i++) { obj2 = (JSONObject) array.get(i); this.result.put("" + obj2.get("wvw_match_id"), new String[] { "" + obj2.get("red_world_id"), "" + obj2.get("blue_world_id"), "" + obj2.get("green_world_id") }); } request.releaseConnection(); this.wvwCheckBox.setEnabled(true); this.interrupt(); } catch (ParseException ex) { try { Logger.getLogger(ApiManager.class.getName()).log(Level.SEVERE, null, ex); request.releaseConnection(); Thread.sleep(3000); } catch (InterruptedException ex1) { Logger.getLogger(WvWMatchReader.class.getName()).log(Level.SEVERE, null, ex1); } } } else { try { Logger.getLogger(EventReader.class.getName()).log(Level.SEVERE, null, "Connection error."); request.releaseConnection(); Thread.sleep(3000); } catch (InterruptedException ex) { Logger.getLogger(HomeWorldAllReader.class.getName()).log(Level.SEVERE, null, ex); this.interrupt(); } } } catch (IOException | IllegalStateException ex) { try { Logger.getLogger(EventReader.class.getName()).log(Level.SEVERE, null, ex); request.releaseConnection(); Thread.sleep(3000); } catch (InterruptedException ex1) { Logger.getLogger(HomeWorldAllReader.class.getName()).log(Level.SEVERE, null, ex1); this.interrupt(); } } } }
From source file:functionaltests.RestSchedulerJobPaginationTest.java
private JSONObject findJob(String id, JSONArray jobs) { for (int i = 0; i < jobs.size(); i++) { if (((JSONObject) jobs.get(i)).get("jobid").equals(id)) { return (JSONObject) jobs.get(i); }/* ww w .j av a2 s .c o m*/ } Assert.fail("Failed to find job " + id + ", all jobs: " + jobs); return null; }