List of usage examples for org.json.simple JSONArray size
public int size()
From source file:io.fabric8.jolokia.assertions.JSONArrayAssert.java
/** * Returns the value at the given index/* w ww .j a v a2 s.co m*/ */ public Object value(int index) { JSONArray array = get(); assertThat(array.size()).as("size of array").isGreaterThan(index); return array.get(index); }
From source file:com.mstiles92.plugins.stileslib.updates.UpdateChecker.java
/** * The task to be run by the Bukkit scheduler that finds the latest published version on BukkitDev. *//*from www .ja v a 2 s .c o m*/ @Override public void run() { try { URL url = new URL("https://api.curseforge.com/servermods/files?projectIds=" + curseProjectId); URLConnection connection = url.openConnection(); connection.setConnectTimeout(5000); connection.setReadTimeout(10000); connection.addRequestProperty("User-Agent", plugin.getName() + " (by mstiles92)"); InputStream stream = connection.getInputStream(); JSONParser parser = new JSONParser(); Object o = parser.parse(new InputStreamReader(stream)); stream.close(); JSONArray array = (JSONArray) o; if (array.size() > 0) { JSONObject latest = (JSONObject) array.get(array.size() - 1); latestVersion = (String) latest.get("name"); latestVersion = latestVersion.substring(1, latestVersion.length()); updateAvailable = isNewerVersion(latestVersion); if (updateAvailable) { plugin.getLogger().info("Update available! New version: " + latestVersion); plugin.getLogger() .info("More information available at http://dev.bukkit.org/bukkit-plugins/" + slug); } } } catch (IOException | ParseException | ClassCastException e) { plugin.getLogger() .info("Unable to check for updates. Will try again later. Error message: " + e.getMessage()); } }
From source file:com.blogspot.jadecalyx.webtools.jcPageObjectHelper.java
private void loadIndexFromJson(String site, String pageHandle) throws Exception { String s = System.getProperty("file.separator"); String runPath = System.getProperty("user.dir"); String fileToRead = pageHandle + ".json"; String fullPath = String.join(s, runPath, "SiteInfo", site, "PageInfo", fileToRead); File f = new File(fullPath); if (!f.isFile()) { throw new Exception( String.format("loadIndex unable to find file for site: %s and file %s", site, fullPath)); }/*from ww w. j ava 2 s . c om*/ //load json file JSONParser parser = new JSONParser(); Object obj = parser.parse(new FileReader(fullPath)); JSONObject jsonObject = (JSONObject) obj; JSONArray objectList = (JSONArray) jsonObject.get("object-list"); try { if (objectList.size() > 0) { for (int i = 0; i < objectList.size(); i++) { JSONObject theObject = (JSONObject) objectList.get(i); JSONArray lookups = (JSONArray) theObject.get("lookup"); List<jcPageObjectSet> currList = new ArrayList<jcPageObjectSet>(); for (int j = (lookups.size() - 1); j > -1; j--) { JSONObject currLookup = (JSONObject) lookups.get(j); currList.add(new jcPageObjectSet(currLookup.get("type").toString(), currLookup.get("detail").toString())); } _objectIndex.put(theObject.get("handle").toString(), currList); } } } catch (Exception e) { int x = 1; } //load include list JSONArray includeList = (JSONArray) jsonObject.get("include-list"); if (includeList.size() > 0) { for (int i = 0; i < includeList.size(); i++) { loadIndexFromJson(site, includeList.get(i).toString()); } } }
From source file:info.mallmc.framework.util.ProfileLoader.java
private void addProperties(GameProfile profile) { String uuid = getUUID(skinOwner); try {/*w w w. ja v a2s . c o m*/ // Get the name from SwordPVP URL url = new URL( "https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false"); URLConnection uc = url.openConnection(); uc.setUseCaches(false); uc.setDefaultUseCaches(false); uc.addRequestProperty("User-Agent", "Mozilla/5.0"); uc.addRequestProperty("Cache-Control", "no-cache, no-store, must-revalidate"); uc.addRequestProperty("Pragma", "no-cache"); // Parse it String json = new Scanner(uc.getInputStream(), "UTF-8").useDelimiter("\\A").next(); JSONParser parser = new JSONParser(); Object obj = parser.parse(json); JSONArray properties = (JSONArray) ((JSONObject) obj).get("properties"); for (int i = 0; i < properties.size(); i++) { try { JSONObject property = (JSONObject) properties.get(i); String name = (String) property.get("name"); String value = (String) property.get("value"); String signature = property.containsKey("signature") ? (String) property.get("signature") : null; if (signature != null) { profile.getProperties().put(name, new Property(name, value, signature)); } else { profile.getProperties().put(name, new Property(value, name)); } } catch (Exception e) { L.ogError(LL.ERROR, Trigger.LOAD, "Failed to apply auth property", "Failed to apply auth property"); } } } catch (Exception e) { ; // Failed to load skin } }
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 v a 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:DOMIC.EncodeJson.java
public EncodeJson(String JsonText) { JSONParser jsonParser = new JSONParser(); try {/*from ww w . ja v a 2 s . c om*/ JSONObject jsonObject = (JSONObject) jsonParser.parse(JsonText); JSONArray test = (JSONArray) jsonObject.get("test"); for (int i = 0; i < test.size(); i++) { JSONArray questionBlock; this.questionBlocks.add(new QuestionBlock()); questionBlock = (JSONArray) test.get(i); for (int j = 0; j < questionBlock.size(); j++) { HashMap questions = (HashMap) questionBlock.get(j); if (questions.get("-oa") != null) { this.questionBlocks.get(i).questions.add(new Question((String) questions.get("-qu"))); JSONArray answerList = null; answerList = (JSONArray) questions.get("-oa"); this.questionBlocks.get(i).questions.get(j).addAnswer(true, (String) answerList.get(0)); } if (questions.get("-sa") != null) { this.questionBlocks.get(i).questions.add(new Question((String) questions.get("-qu"))); JSONArray answerList = null; answerList = (JSONArray) questions.get("-sa"); for (int k = 0; k < answerList.size(); k++) { this.questionBlocks.get(i).questions.get(j).addAnswer(true, (String) answerList.get(k)); } } if (questions.get("-ma") != null) { this.questionBlocks.get(i).questions.add(new Question((String) questions.get("-qu"))); JSONArray answerList = null; answerList = (JSONArray) questions.get("-ma"); JSONArray trueAnswer = (JSONArray) answerList.get(0); JSONArray falseAnswer = (JSONArray) answerList.get(1); for (int k = 0; k < trueAnswer.size(); k++) { this.questionBlocks.get(i).questions.get(j).addAnswer(true, (String) trueAnswer.get(k)); } for (int k = 0; k < falseAnswer.size(); k++) { this.questionBlocks.get(i).questions.get(j).addAnswer(false, (String) falseAnswer.get(k)); } } } } System.out.println(""); } catch (ParseException e) { e.printStackTrace(); } }
From source file:com.shazam.dataengineering.pipelinebuilder.DeploymentLog.java
public List<Deployment> getAll() { JSONArray deployments = (JSONArray) log.get(ROOT); ArrayList<Deployment> deploymentArrayList = new ArrayList<Deployment>(); for (int i = 0; i < deployments.size(); i++) { deploymentArrayList.add(new Deployment((JSONObject) deployments.get(i))); }/*from www . j a va2s . co m*/ return deploymentArrayList; }
From source file:lockers.FrameCobro.java
private void getRates() { JSONArray array = Utils.getJSONArrayFromURL("http://127.0.0.1:8000/Rates/?format=json"); if (array.size() == 0) { this.jLblAvailableLockers.setText("No hay disponibilidad"); } else {/*from w w w .j a v a 2s .c om*/ for (Object array1 : array) { JButton nuevo = new JButton(); JSONObject obj2 = (JSONObject) array1; System.out.println(obj2.size()); nuevo.setText(obj2.get("rate_name") + ": " + obj2.get("rate_rate")); nuevo.setVisible(true); nuevo.setSize(200, 50); nuevo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source instanceof JButton) { JButton btn = (JButton) source; System.out.println("You clicked the button " + btn.getText()); } } }); this.jPanel1.add(nuevo); } } }
From source file:com.ge.research.semtk.sparqlX.SparqlEndpointInterface.java
/** * Parse an auth query confirmation. The message will the first entry in the rows array. * @param rowsJsonArray//from www . j av a 2 s .co m * @return */ private static String getAuthMessageFromResponse(JSONArray rowsJsonArray) { String message = ""; for (int i = 0; i < rowsJsonArray.size(); i++) { JSONObject row = (JSONObject) rowsJsonArray.get(i); // e.g. {"callret-0":{"type":"literal","value":"Insert into <http:\/\/research.ge.com\/dataset>, 1 (or less) triples -- done"}} JSONObject value; String key, valueValue; @SuppressWarnings("unchecked") Iterator<String> iter = row.keySet().iterator(); while (iter.hasNext()) { key = (String) iter.next(); value = (JSONObject) row.get(key); valueValue = (String) value.get("value"); message += valueValue; } } return message; }
From source file:fr.lirmm.yamplusplus.yampponline.TestOaeiAlignment.java
@Test public void testOaeiAlignment() throws IOException, ClassNotFoundException, OWLOntologyStorageException, SAXException { String iamlRameauAlignment = FileUtils .readFileToString(new File("src/test/resources/iaml-rameau_valid_test.rdf"), "UTF-8"); boolean testExtractValid = false; YamFileHandler fileHandler = new YamFileHandler(); JSONObject parseOaeiJson = new JSONObject(); parseOaeiJson = fileHandler.parseOaeiAlignmentFormat(iamlRameauAlignment); JSONArray entities = (JSONArray) parseOaeiJson.get("entities"); // Look for a specific valid mapping to test if parsing worked for (int i = 0; i < entities.size(); i++) { JSONObject mappingJObject = (JSONObject) entities.get(i); if (mappingJObject.get("valid").equals("valid") && mappingJObject.get("entity1").equals("http://iflastandards.info/ns/unimarc/terms/mop/wdb") && mappingJObject.get("entity2").equals("http://data.bnf.fr/ark:/12148/cb12270245r")) { testExtractValid = true;/*from ww w . j a v a 2 s . c om*/ break; } } //System.out.println(parseOaeiJson.toString()); assertTrue(testExtractValid); }