List of usage examples for org.json.simple JSONArray size
public int size()
From source file:JavaCloud.Api.java
public ArrayList<String> ciModulesList() throws CoreException { JSONObject object = new JSONObject(); object.put("token", token); JSONArray jsonmodules = (JSONArray) Utils.request(address, "/api/api/list_ci_modules/", object); ArrayList<String> modules = new ArrayList<String>(); for (int i = 0; i < jsonmodules.size(); i++) { modules.add(jsonmodules.get(i).toString()); }/*from w ww.j av a2 s .co m*/ return modules; }
From source file:JavaCloud.Api.java
public ArrayList<String> apiModulesList() throws CoreException { JSONObject object = new JSONObject(); object.put("token", token); JSONArray jsonmodules = (JSONArray) Utils.request(address, "/api/api/list_api_modules/", object); ArrayList<String> modules = new ArrayList<String>(); for (int i = 0; i < jsonmodules.size(); i++) { modules.add(jsonmodules.get(i).toString()); }//from ww w . j av a2 s.com return modules; }
From source file:me.neatmonster.spacertk.plugins.templates.Version.java
/** * Creates a new version/*from w w w . j a v a 2 s . c o m*/ * @param version JSONObject containing the raw information from BukGet */ public Version(final JSONObject version) { date = (Long) version.get("date"); name = (String) version.get("name"); filename = (String) version.get("filename"); md5 = (String) version.get("md5"); link = (String) version.get("download"); final JSONArray buildsJSONArray = (JSONArray) version.get("game_versions"); @SuppressWarnings("unchecked") final List<Object> buildsListObject = buildsJSONArray.subList(0, buildsJSONArray.size()); for (final Object object : buildsListObject) builds.add((String) object); if (!(version.get("soft_dependencies") instanceof String)) {//Assuming empty list if String final JSONArray softDependenciesJSONArray = (JSONArray) version.get("soft_dependencies"); @SuppressWarnings("unchecked") final List<Object> softDependenciesListObject = softDependenciesJSONArray.subList(0, softDependenciesJSONArray.size()); for (final Object object : softDependenciesListObject) softDependencies.add((String) object); } if (!(version.get("hard_dependencies") instanceof String)) { //Assuming empty list if String final JSONArray hardDependenciesJSONArray = (JSONArray) version.get("hard_dependencies"); @SuppressWarnings("unchecked") final List<Object> hardDependenciesListObject = hardDependenciesJSONArray.subList(0, hardDependenciesJSONArray.size()); for (final Object object : hardDependenciesListObject) hardDependencies.add((String) object); } }
From source file:control.ParametrizacionServlets.ActualizarPuntoVertimiento.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w w w .j ava 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 { JSONObject resError = new JSONObject(); try { //Obtenemos el numero de contrato Double contrato = Double.parseDouble(request.getParameter("contrato")); //Obtenemos la cadena con la informacion y la convertimos en un //JSONArray String puntos = request.getParameter("puntos"); Object obj = JSONValue.parse(puntos); 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); String ubicacion = (String) jsonObject.get("ubicacion"); String latitud = (String) jsonObject.get("latitud"); String longitud = (String) jsonObject.get("longitud"); String observacion = (String) jsonObject.get("observacion"); int estado = Integer.parseInt((String) jsonObject.get("estado")); String codigo = (String) jsonObject.get("codigo"); String tipoEstructura = (String) jsonObject.get("tipoEstructura"); //Creamos el manager y guardamos la informacion. PuntosVertimiento manager = new PuntosVertimiento(); manager.actualizar(codigo, ubicacion, latitud, longitud, observacion, estado, contrato, tipoEstructura); } resError.put("error", 1); } catch (Exception ex) { resError.put("error", 0); } }
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))); }// ww w . java 2 s.c o m return templates; }
From source file:com.googlecode.fascinator.portal.process.RecordProcessor.java
/** * 'pre' - processing method.//from w w w.j av a 2 s . c o m * * The Solr Query is executed and the resulting ID HashSet is stored on the * dataMap as the 'outputKey', along with any entries from 'includeList' * config entry. To manually process a certain record(s), add the id on the * 'includeList'. Processing will read the 'lastRun' config entry and pulls * records since then. <br/> * * @param id * @param outputKey * @param configFilePath * @param dataMap * @return * @throws Exception */ private boolean getRecords(String id, String outputKey, String configFilePath, HashMap<String, Object> dataMap) throws Exception { Indexer indexer = (Indexer) dataMap.get("indexer"); JsonSimple config = new JsonSimple(new File(configFilePath)); String solrQuery = config.getString("", "query"); String lastRun = config.getString(null, "lastrun"); solrQuery += (lastRun != null ? " AND create_timestamp:[" + lastRun + " TO NOW]" : ""); log.debug("Using solrQuery:" + solrQuery); SearchRequest searchRequest = new SearchRequest(solrQuery); int start = 0; int pageSize = 10; searchRequest.setParam("start", "" + start); searchRequest.setParam("rows", "" + pageSize); ByteArrayOutputStream result = new ByteArrayOutputStream(); indexer.search(searchRequest, result); SolrResult resultObject = new SolrResult(result.toString()); int numFound = resultObject.getNumFound(); log.debug("Number found:" + numFound); HashSet<String> newRecords = new HashSet<String>(); while (true) { List<SolrDoc> results = resultObject.getResults(); for (SolrDoc docObject : results) { String oid = docObject.getString(null, "id"); if (oid != null) { log.debug("Record found: " + oid); newRecords.add(oid); } else { log.debug("Record returned but has no id."); log.debug(docObject.toString()); } } start += pageSize; if (start > numFound) { break; } searchRequest.setParam("start", "" + start); result = new ByteArrayOutputStream(); indexer.search(searchRequest, result); resultObject = new SolrResult(result.toString()); } // get the exception list.. JSONArray includedArr = config.getArray("includeList"); if (includedArr != null && includedArr.size() > 0) { newRecords.addAll(includedArr); } dataMap.put(outputKey, newRecords); return true; }
From source file:control.ParametrizacionServlets.ActualizarLaboratorios.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w ww .ja 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 */ @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"); Integer codigo = Integer.parseInt(request.getParameter("codigo")); String paramAcreditados = request.getParameter("paramAcreditados"); Laboratorios manager = new Laboratorios(); manager.actualizar(nombre, contactos, direccion, telefono, telefono2, correo, resolucion, vigencia, codigo); int resp = 0; //Obtenemos La informacion del manager AcreditacionParametros managerAcreditacion = new AcreditacionParametros(); //Eliminamos lo parametros resp = managerAcreditacion.eliminar(codigo); 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, codigo); } } catch (Exception e) { } }
From source file:NetworkController.java
public Network networkResponse(String hostid, PutMethod putMethod, String name) { JSONParser parser = new JSONParser(); String loginResponse = ""; HttpClient client = new HttpClient(); try {// www . j av a2s . c o m client.executeMethod(putMethod); // send to request to the zabbix api loginResponse = putMethod.getResponseBodyAsString(); // read the result of the response Object obj = parser.parse(loginResponse); JSONObject obj2 = (JSONObject) obj; String jsonrpc = (String) obj2.get("jsonrpc"); JSONArray array = (JSONArray) obj2.get("result"); for (int i = 0; i < array.size(); i++) { JSONObject tobj = (JSONObject) array.get(i); if (!tobj.get("hostid").equals(hostid)) continue; if (comparision(name, "loOut", tobj, LOOUT)) return getNetwork(tobj, hostid, LOOUT); else if (comparision(name, "loIn", tobj, LOIN)) return getNetwork(tobj, hostid, LOIN); else if (comparision(name, "eth1Out", tobj, ETH1OUT)) return getNetwork(tobj, hostid, ETH1OUT); else if (comparision(name, "eth0Out", tobj, ETH0OUT)) return getNetwork(tobj, hostid, ETH0OUT); else if (comparision(name, "eth0In", tobj, ETH0IN)) return getNetwork(tobj, hostid, ETH0IN); else if (comparision(name, "eth1In", tobj, ETH1IN)) return getNetwork(tobj, hostid, ETH1IN); else if (comparision(name, "latency", tobj, LATENCY)) return getNetwork(tobj, hostid, LATENCY); else if (comparision(name, "packetloss", tobj, PACKETLOSS)) return getNetwork(tobj, hostid, PACKETLOSS); else continue; } } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException pe) { System.out.println("Error"); } return new Network( "Error: please provide the appropriate input parameters of the metric you are looking for its corresponding monitoring data:"); }
From source file:graphvk.Search.java
public ArrayList<String> zaprosSearch() throws IOException { String strUrl = ""; String resultSeachJson;//from ww w .java2s . co m strUrl = urlApi + methodUusersSearch + paramsSearch + "&count=1000" + "&access_token=" + accessToken; File file = new File(pathOne); //? ??. if (!file.exists()) { // . file.createNewFile(); } URL url = new URL(strUrl); // ? API VK UserSearch BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); resultSeachJson = reader.readLine(); reader.close(); JSONParser parser = new JSONParser(); // ? Json try { Object objS = parser.parse(resultSeachJson); JSONObject jsonSObject = (JSONObject) objS; JSONArray listResult = (JSONArray) jsonSObject.get("response"); JSONObject jsonSObj; for (int i = 1; i < listResult.size() - 1; i++) { jsonSObj = (JSONObject) listResult.get(i); userListSearch1.add("" + jsonSObj.get("uid")); } } catch (Exception e) { System.out.println(" Search "); } return userListSearch1; }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.viewer.MapperProxy.java
@Override public void run() { running = true;/*ww w . j a v a 2 s.co 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) { } } }