List of usage examples for org.json.simple JSONArray get
public E get(int index)
From source file:at.rocworks.oa4j.logger.logger.DataSink.java
private void createGroups() { // Logging Groups JDebug.out.info("logging groups..."); int gcount;//from w ww. j a va 2s. c o m String gprimary = settings.getStringProperty("logger", "primary", ""); String sgroups = settings.getStringProperty("logger", "groups", ""); try { JSONArray jgroups = (JSONArray) JSONValue.parse(sgroups); gcount = jgroups.size(); for (int j = 0; j < gcount; j++) { if (createGroup(settings, jgroups.get(j).toString())) { if (gprimary.isEmpty()) { gprimary = jgroups.get(j).toString(); } } } JDebug.out.log(Level.CONFIG, "primary={0}", gprimary); logger.setReadGroup(gprimary); } catch (java.lang.ClassCastException ex) { JDebug.out.log(Level.SEVERE, "not a valid json group string '{0} [{1}]'!", new Object[] { sgroups, ex.toString() }); } }
From source file:com.mcapanel.utils.ErrorHandler.java
private ObfuscatedString v(Object rb) { JSONArray qg = (JSONArray) rb; long[] nc = new long[qg.size()]; for (int i = 0; i < qg.size(); i++) { nc[i] = (Long) qg.get(i); }// w w w . ja v a 2 s . c o m return new ObfuscatedString(nc); }
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 w w . j av a2 s. c o 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()); }/*w w w . j a v a 2 s . com*/ return modules; }
From source file:fr.itldev.koya.webscript.content.ZipContent.java
@Override public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException { Map<String, Object> jsonPostMap = KoyaWebscript.getJsonMap(req); ArrayList<String> nodeRefs = new ArrayList<>(); JSONArray jsonArray = (JSONArray) jsonPostMap.get(ARG_NODEREFS); if (jsonArray != null) { int len = jsonArray.size(); for (int i = 0; i < len; i++) { nodeRefs.add(jsonArray.get(i).toString()); }// w ww. ja va 2s. c o m } try { res.setContentType(MIMETYPE_ZIP); res.setHeader("Content-Transfer-Encoding", "binary"); res.addHeader("Content-Disposition", "attachment"); res.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); res.setHeader("Pragma", "public"); res.setHeader("Expires", "0"); File tmpZipFile = koyaContentService.zip(nodeRefs); OutputStream outputStream = res.getOutputStream(); if (nodeRefs.size() > 0) { InputStream in = new FileInputStream(tmpZipFile); try { byte[] buffer = new byte[8192]; int len; while ((len = in.read(buffer)) > 0) { outputStream.write(buffer, 0, len); } } finally { IOUtils.closeQuietly(in); } } } catch (KoyaServiceException ex) { throw new WebScriptException("KoyaError : " + ex.getErrorCode().toString()); } catch (RuntimeException e) { /** * TODO koya specific exception */ throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Erreur lors de la gnration de l'archive.", e); } }
From source file:JavaCloud.Api.java
public ArrayList<VM> vmList() throws CoreException { JSONObject object = new JSONObject(); object.put("token", token); JSONArray jsonvms = (JSONArray) Utils.request(address, "/api/vm/get_list/", object); ArrayList<VM> vms = new ArrayList<VM>(); for (int i = 0; i < jsonvms.size(); i++) { vms.add(new VM(address, token, (JSONObject) jsonvms.get(i))); }//www.j a va 2 s . co m return vms; }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.algorithm.VehicleStatus.java
public VehicleStatus(JSONObject obj) { name = (String) obj.get("name"); id = (String) obj.get("vehicle.id"); state = Status.valueOf(((String) obj.get("state")).toUpperCase()); if (state == Status.ACTIVE || state == Status.SUSPENDED) { Double latitude = (Double) obj.get("latitude"); Double longitude = (Double) obj.get("longitude"); Double altitude = (Double) obj.get("altitude"); if (latitude != null && longitude != null && altitude != null) { position = new PolarCoordinate(latitude.doubleValue(), longitude.doubleValue(), altitude.doubleValue()); } else {/*from w ww . ja va 2s. c o m*/ position = null; } Double t = (Double) obj.get("tolerance"); tolerance = t != null ? t.doubleValue() : 5.0; JSONArray as = (JSONArray) obj.get("actions"); actions = new HashSet<String>(); if (as != null) { for (int k = 0; k < as.size(); ++k) { actions.add((String) as.get(k)); } } } }
From source file:com.ibm.bluemix.hack.image.ImageEvaluator.java
@SuppressWarnings("unchecked") public JSONObject analyzeImage(byte[] buf) throws IOException { JSONObject imageProcessingResults = new JSONObject(); JSONObject creds = VcapServicesHelper.getCredentials("watson_vision_combined", null); String baseUrl = creds.get("url").toString(); String apiKey = creds.get("api_key").toString(); String detectFacesUrl = baseUrl + "/v3/detect_faces?api_key=" + apiKey + "&version=2016-05-20"; String classifyUrl = baseUrl + "/v3/classify?api_key=" + apiKey + "&version=2016-05-20"; OkHttpClient client = new OkHttpClient(); RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM) .addFormDataPart("images_file", "sample.jpg", RequestBody.create(MediaType.parse("image/jpg"), buf)) .build();//from www . j a v a 2 s.c o m Request request = new Request.Builder().url(detectFacesUrl).post(requestBody).build(); Response response = client.newCall(request).execute(); String result = response.body().string(); JSONParser jsonParser = new JSONParser(); try { JSONObject results = (JSONObject) jsonParser.parse(result); // since we only process one image at a time, let's simplfy the json // we send to the JSP. JSONArray images = (JSONArray) results.get("images"); if (images != null && images.size() > 0) { JSONObject firstImage = (JSONObject) images.get(0); JSONArray faces = (JSONArray) firstImage.get("faces"); imageProcessingResults.put("faces", faces); } } catch (ParseException e) { e.printStackTrace(); } // now request classification request = new Request.Builder().url(classifyUrl).post(requestBody).build(); response = client.newCall(request).execute(); result = response.body().string(); try { JSONObject results = (JSONObject) jsonParser.parse(result); // since we only process one image at a time, let's simplfy the json // we send to the JSP. JSONArray images = (JSONArray) results.get("images"); if (images != null && images.size() > 0) { JSONObject firstImage = (JSONObject) images.get(0); JSONArray classifiers = (JSONArray) firstImage.get("classifiers"); imageProcessingResults.put("classifiers", classifiers); } } catch (ParseException e) { e.printStackTrace(); } return imageProcessingResults; }
From source file:eumetsat.pn.solr.SolrFeeder.java
private SolrInputDocument createInputDoc(JSONObject jsObj) { SolrInputDocument input = new SolrInputDocument(); // field values should match schema.xml // solr can add new fields on the fly: http://heliosearch.org/solr/getting-started/ String id = (String) jsObj.get(FILE_IDENTIFIER_PROPERTY); input.addField("id", id); JSONObject info = (JSONObject) jsObj.get("identificationInfo"); input.addField("title", info.get("title")); input.addField("description", info.get("abstract")); if (!info.get("thumbnail").toString().isEmpty()) { input.addField("thumbnail_s", info.get("thumbnail")); }//from w w w .j ava2 s. co m JSONArray keywords = (JSONArray) info.get("keywords"); if (!keywords.isEmpty()) { input.addField("keywords", keywords.toArray()); } if (!info.get("status").toString().isEmpty()) { input.addField("status_s", info.get("status")); } JSONObject hierarchy = (JSONObject) jsObj.get("hierarchyNames"); //public static final ImmutableMap<String, String> FACETS2HIERACHYNAMES = ImmutableMap.of("satellites", "hierarchyNames.satellite", //"instruments", "hierarchyNames.instrument", //"categories", "hierarchyNames.category", //"societalBenefitArea", "hierarchyNames.societalBenefitArea", //"distribution", "hierarchyNames.distribution"); if (hierarchy.get("satellite") != null && !hierarchy.get("satellite").toString().isEmpty()) { input.addField("satellite_s", hierarchy.get("satellite")); } if (hierarchy.get("instrument") != null && !hierarchy.get("instrument").toString().isEmpty()) { input.addField("instrument_s", hierarchy.get("instrument")); } JSONArray categories = (JSONArray) hierarchy.get("category"); if (categories != null && !categories.isEmpty()) { input.addField("category", categories); } JSONArray sbas = (JSONArray) hierarchy.get("societalBenefitArea"); if (sbas != null && !sbas.isEmpty()) { input.addField("societalBenefitArea_ss", sbas); } Collection<String> distrs = (Collection<String>) hierarchy.get("distribution"); if (distrs != null && !distrs.isEmpty()) { input.addField("distribution_ss", distrs); } // https://cwiki.apache.org/confluence/display/solr/Spatial+Search JSONObject location = (JSONObject) jsObj.get("location"); String type = (String) location.get("type"); if ("envelope".equals(type)) { StringBuilder envelope = new StringBuilder(); // ISO2JSON: envelope.add(leftTopPt); envelope.add(rightDownPt); JSONArray coords = (JSONArray) location.get("coordinates"); JSONArray leftTopPoint = (JSONArray) coords.get(0); JSONArray rightDownPoint = (JSONArray) coords.get(1); // Spatial search envelope: minX, maxX, maxY, minY envelope.append("ENVELOPE(").append(leftTopPoint.get(0)).append(", "); envelope.append(rightDownPoint.get(0)).append(", "); envelope.append(leftTopPoint.get(1)).append(", "); envelope.append(rightDownPoint.get(1)).append(")"); input.addField("boundingbox", envelope.toString()); } else { log.warn("Unsupported location field value: {}", location.toJSONString()); } JSONObject contact = (JSONObject) jsObj.get("contact"); input.addField("email_s", contact.get("email")); input.addField("address_s", contact.get("address")); input.addField("xmldoc", jsObj.get("xmldoc")); return input; }
From source file:com.des.paperbase.ManageData.java
public void delete(String Tablename, Map<String, Object> value, String FilterType) throws ParseException, IOException { String data = g.readFileToString(PATH_FILE + "\\" + Tablename + ".json"); List<Integer> ListDelete = new LinkedList<Integer>(); if (!data.equalsIgnoreCase("{\"data\":[]}")) { JSONObject json = (JSONObject) new JSONParser().parse(data); JSONArray OldValue = (JSONArray) json.get("data"); for (int s = 0; s < OldValue.size(); s++) { JSONObject record = (JSONObject) OldValue.get(s); if (MappingRecordAndKey(value, record, FilterType)) { ListDelete.add(s);//w ww .ja va 2s . c o m } } for (int i = ListDelete.size() - 1; i >= 0; i--) { System.out.print(ListDelete.get(i) + " "); OldValue.remove(ListDelete.get(i).intValue()); } JSONObject table = new JSONObject(); table.put("data", OldValue); g.writefile(table.toJSONString(), PATH_FILE + "\\" + Tablename + ".json"); } }