List of usage examples for org.json.simple JSONObject get
V get(Object key);
From source file:com.serena.rlc.provider.jira.domain.Issue.java
public static List<Issue> parse(String options) { List<Issue> list = new ArrayList<Issue>(); JSONParser parser = new JSONParser(); try {/* w w w . j a v a 2 s .c o m*/ Object parsedObject = parser.parse(options); JSONArray array = (JSONArray) ((JSONObject) parsedObject).get("issues"); for (Object object : array) { Issue obj = new Issue(); JSONObject jsonObject = (JSONObject) object; JSONObject fieldsObject = (JSONObject) jsonObject.get("fields"); JSONObject typeObject = (JSONObject) fieldsObject.get("issuetype"); JSONObject statusObject = (JSONObject) fieldsObject.get("status"); JSONObject projectObject = (JSONObject) fieldsObject.get("project"); JSONObject creatorObject = (JSONObject) fieldsObject.get("creator"); JSONObject priorityObject = (JSONObject) fieldsObject.get("priority"); obj.setId((String) jsonObject.get("key")); obj.setUrl((String) jsonObject.get("key")); obj.setName((String) fieldsObject.get("summary")); obj.setDescription((String) fieldsObject.get("description")); obj.setDateCreated((String) fieldsObject.get("created")); obj.setLastUpdated((String) fieldsObject.get("updated")); obj.setType((String) typeObject.get("name")); obj.setStatus((String) statusObject.get("name")); obj.setProject((String) projectObject.get("name")); obj.setCreator((String) creatorObject.get("name")); obj.setPriority((String) priorityObject.get("name")); list.add(obj); } } catch (ParseException e) { logger.error("Error while parsing input JSON - " + options, e); } return list; }
From source file:cpd3314.buildit12.CPD3314BuildIt12.java
/** * Build a sample method that saves a handful of car instances as Serialized * objects, and as JSON objects, then re-open the saved versions in a * different method/*from w w w . j a v a 2 s . c o m*/ */ public static void doBuildIt2Input() { // Unserialize the Objects -- Save them to an ArrayList and Output try { FileInputStream objFile = new FileInputStream("cars.obj"); ObjectInputStream objStream = new ObjectInputStream(objFile); ArrayList<Car> cars = new ArrayList<>(); boolean eof = false; while (!eof) { try { cars.add((Car) objStream.readObject()); } catch (ClassNotFoundException ex) { Logger.getLogger(CPD3314BuildIt12.class.getName()).log(Level.SEVERE, null, ex); } catch (EOFException ex) { // We must catch the EOF exception to leave the loop eof = true; } } System.out.println("Unserialized Data:"); for (Car car : cars) { System.out.printf("Make: %s, Model: %s, Year: %d\n", car.getMake(), car.getModel(), car.getYear()); } } catch (IOException ex) { Logger.getLogger(CPD3314BuildIt12.class.getName()).log(Level.SEVERE, null, ex); } // Read from JSON and Output try { File file = new File("cars.json"); Scanner input = new Scanner(file); while (input.hasNext()) { JSONParser parse = new JSONParser(); try { // This should be the root JSON Object, which has an array of Car objects JSONObject json = (JSONObject) parse.parse(input.nextLine()); // We pull the array out to work with it JSONArray cars = (JSONArray) json.get("cars"); System.out.println("Un-JSON-ed Data:"); for (Object car : cars) { // Convert each Object to a JSONObject JSONObject carJSON = (JSONObject) car; // Convert each JSONObject to an actual Car Car carObj = new Car(carJSON); // Output from the Actual Car class System.out.printf("Make: %s, Model: %s, Year: %d\n", carObj.getMake(), carObj.getModel(), carObj.getYear()); } } catch (ParseException ex) { Logger.getLogger(CPD3314BuildIt12.class.getName()).log(Level.SEVERE, null, ex); } } } catch (IOException ex) { Logger.getLogger(CPD3314BuildIt12.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:model.Post_store.java
public static List<String> getpostUAcomments(int id) { JSONParser parser = new JSONParser(); List<String> UA_comments = new ArrayList<>(); try {/*from w w w . ja v a2 s . com*/ Object obj = parser.parse(new FileReader(root + "posts/" + id + ".json")); JSONObject jsonObject = (JSONObject) obj; JSONArray JUAcomments = (JSONArray) jsonObject.get("UA_comments"); if (JUAcomments != null) { Iterator<String> iterator = JUAcomments.iterator(); while (iterator.hasNext()) { UA_comments.add(iterator.next()); } } } catch (FileNotFoundException e) { System.out.println(e); } catch (IOException e) { System.out.println(e); } catch (ParseException e) { System.out.println(e); } return UA_comments; }
From source file:fr.free.movierenamer.utils.JSONUtils.java
public static List<JSONObject> selectList(String path, final JSONObject rootObject) { try {//w w w.j av a2 s . c om JSONObject toSearch = rootObject; int last = path.lastIndexOf('/'); if (last >= 0) { toSearch = selectObject(path.substring(0, last), toSearch); } JSONArray array = (JSONArray) toSearch.get(path.substring(last + 1, path.length())); return jsonList(array); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:me.fromgate.facechat.UpdateChecker.java
private static void updateLastVersion() { if (!enableUpdateChecker) return;/*from w w w. j a va 2 s. c o m*/ URL url = null; try { url = new URL(projectApiUrl); } catch (Exception e) { log("Failed to create URL: " + projectApiUrl); return; } try { URLConnection conn = url.openConnection(); conn.addRequestProperty("X-API-Key", null); conn.addRequestProperty("User-Agent", projectName + " using UpdateChecker (by fromgate)"); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); String response = reader.readLine(); JSONArray array = (JSONArray) JSONValue.parse(response); if (array.size() > 0) { JSONObject latest = (JSONObject) array.get(array.size() - 1); String plugin_name = (String) latest.get("name"); projectLastVersion = plugin_name.replace(projectName + " v", "").trim(); } } catch (Exception e) { log("Failed to check last version"); } }
From source file:net.amigocraft.mpt.command.InstallCommand.java
@SuppressWarnings("unchecked") public static void downloadPackage(String id) throws MPTException { JSONObject packages = (JSONObject) Main.packageStore.get("packages"); if (packages != null) { JSONObject pack = (JSONObject) packages.get(id); if (pack != null) { if (pack.containsKey("name") && pack.containsKey("version") && pack.containsKey("url")) { if (pack.containsKey("sha1") || !Config.ENFORCE_CHECKSUM) { String name = pack.get("name").toString(); String version = pack.get("version").toString(); String fullName = name + " v" + version; String url = pack.get("url").toString(); String sha1 = pack.containsKey("sha1") ? pack.get("sha1").toString() : ""; if (pack.containsKey("installed")) { //TODO: compare versions throw new MPTException(ID_COLOR + name + ERROR_COLOR + " is already installed"); }// w w w . ja v a2s. c om try { URLConnection conn = new URL(url).openConnection(); conn.connect(); ReadableByteChannel rbc = Channels.newChannel(conn.getInputStream()); File file = new File(Main.plugin.getDataFolder(), "cache" + File.separator + id + ".zip"); file.setReadable(true, false); file.setWritable(true, false); file.getParentFile().mkdirs(); file.createNewFile(); FileOutputStream os = new FileOutputStream(file); os.getChannel().transferFrom(rbc, 0, MiscUtil.getFileSize(new URL(url))); os.close(); if (!sha1.isEmpty() && !sha1(file.getAbsolutePath()).equals(sha1)) { file.delete(); throw new MPTException(ERROR_COLOR + "Failed to install package " + ID_COLOR + fullName + ERROR_COLOR + ": checksum mismatch!"); } } catch (IOException ex) { throw new MPTException( ERROR_COLOR + "Failed to download package " + ID_COLOR + fullName); } } else throw new MPTException(ERROR_COLOR + "Package " + ID_COLOR + id + ERROR_COLOR + " is missing SHA-1 checksum! Aborting..."); } else throw new MPTException(ERROR_COLOR + "Package " + ID_COLOR + id + ERROR_COLOR + " is missing required elements!"); } else throw new MPTException(ERROR_COLOR + "Cannot find package with id " + ID_COLOR + id); } else { throw new MPTException(ERROR_COLOR + "Package store is malformed!"); } }
From source file:info.usbo.skypetwitter.Run.java
private static void vk() throws ParseException { String url = "https://api.vk.com/method/wall.get?v=5.28&domain=Depersonilized&filter=owner&extended=1"; String line = ""; try {/*from w ww . j av a 2 s.co m*/ URL url2 = new URL(url); BufferedReader reader = new BufferedReader(new InputStreamReader(url2.openStream(), "UTF-8")); line = reader.readLine(); reader.close(); } catch (MalformedURLException e) { // ... } catch (IOException e) { // ... } JSONObject json = (JSONObject) new JSONParser().parse(line); json = (JSONObject) new JSONParser().parse(json.get("response").toString()); JSONArray jsona = (JSONArray) new JSONParser().parse(json.get("items").toString()); vk.clear(); for (int i = 0; i < jsona.size(); i++) { vk.add(new VK(jsona.get(i).toString())); } }
From source file:com.sugarcrm.candybean.configuration.Configuration.java
public static String getPlatformValue(Properties props, String key) { String platform = Utils.getCurrentPlatform(); String valueStr = props.getProperty(key); JSONParser parser = new JSONParser(); try {//from w w w . j ava2 s . co m Object valueObject = parser.parse(valueStr); if (valueObject instanceof Map) { JSONObject valueMap = (JSONObject) valueObject; return (String) valueMap.get(platform); } else { return valueStr; } } catch (ParseException pe) { return valueStr; } }
From source file:iracing.webapi.LicenseGroupParser.java
public static List<LicenseGroup> parse(String json) { JSONParser parser = new JSONParser(); List<LicenseGroup> output = null; try {/*from ww w. ja va 2 s . com*/ JSONArray rootArray = (JSONArray) parser.parse(json); output = new ArrayList<LicenseGroup>(); for (int i = 0; i < rootArray.size(); i++) { JSONObject r = (JSONObject) rootArray.get(i); LicenseGroup lg = new LicenseGroup(); lg.setId(getInt(r, "group")); lg.setName(getString(r, "name", true)); // NOTE: the following aren't specified if not applicable Object o = r.get("minNumTT"); if (o != null) lg.setMinimumNumberOfTimeTrials(((Long) o).intValue()); o = r.get("minNumRaces"); if (o != null) lg.setMinimumNumberOfRaces(((Long) o).intValue()); output.add(lg); } } catch (ParseException ex) { Logger.getLogger(LicenseGroupParser.class.getName()).log(Level.SEVERE, null, ex); } return output; }
From source file:eu.dety.burp.joseph.utilities.Converter.java
/** * Get RSA PublicKey by JWK JSON input/* ww w . j a v a 2s . c o m*/ * * @param input * JSON Web Key {@link JSONObject} * @return {@link PublicKey} or null */ private static PublicKey getRsaPublicKeyByJwk(JSONObject input) { if (!input.containsKey("kty")) return null; String kty = (String) input.get("kty"); if (kty.equals("RSA")) return buildRsaPublicKeyByJwk(input); return null; }