List of usage examples for org.json.simple JSONObject get
V get(Object key);
From source file:com.serena.rlc.provider.jenkins.domain.Job.java
public static List<Job> parse(String options) { List<Job> list = new ArrayList<>(); JSONParser parser = new JSONParser(); try {/*from ww w. j ava2 s . c o m*/ Object parsedObject = parser.parse(options); JSONArray array = (JSONArray) ((JSONObject) parsedObject).get("jobs"); for (Object object : array) { Job obj = new Job(); JSONObject jsonObject = (JSONObject) object; // JSONObject nameObject = (JSONObject)jsonObject.get("name"); // JSONObject displayNameObject = (JSONObject)jsonObject.get("displayName"); obj.setName((String) jsonObject.get("name")); obj.setDisplayName((String) jsonObject.get("displayName")); list.add(obj); } } catch (ParseException e) { logger.error("Error while parsing input JSON - " + options, e); } return list; }
From source file:com.storageroomapp.client.PageOfEntries.java
/** * Parses a String of json text and returns an PageOfEntries object. * It will correctly parse the PageOfEntries object if it is toplevel, * or also if nested in an 'array' key-value pair. * /* w w w . j a v a 2 s . c o m*/ * @param json the String with the json text * @return an PageOfEntries object, or null if the parsing failed */ static public PageOfEntries parseJSON(Collection parent, String json) { if (json == null) { return null; } JSONObject jsonObj = (JSONObject) JSONValue.parse(json); if (jsonObj == null) { return null; } JSONObject jsonArrayObj = (JSONObject) jsonObj.get("array"); if (jsonArrayObj != null) { jsonObj = jsonArrayObj; } return parseJSONObject(parent, jsonObj); }
From source file:com.storageroomapp.client.field.ImageVersion.java
static public List<ImageVersion> parseJSONListObject(JSONObject jsonObj) { @SuppressWarnings("unchecked") Set<String> identifiers = (Set<String>) jsonObj.keySet(); List<ImageVersion> versions = new ArrayList<ImageVersion>(); for (String identifier : identifiers) { JSONObject versionObject = (JSONObject) jsonObj.get(identifier); String url = (String) versionObject.get("@url"); if (url != null) { ImageVersion newVersion = new ImageVersion(identifier, url); versions.add(newVersion);//from ww w . j a v a 2 s. c o m } } return versions; }
From source file:mml.handler.scratch.Scratch.java
protected static EcdosisMVD doGetMVD(String db, String docid) throws DbException { String res = null;// www . ja v a2 s.c o m JSONObject jDoc = null; res = Connector.getConnection().getFromDb(db, docid); if (res != null) jDoc = (JSONObject) JSONValue.parse(res); if (jDoc != null) { String format = (String) jDoc.get(JSONKeys.FORMAT); if (format != null) { return new EcdosisMVD(jDoc); } } return null; }
From source file:mml.handler.scratch.ScratchVersion.java
/** * Convert a BSON object to a Scratch version internal format * @param json the bson object from the database * @return a ScratchVersion with layers/*w w w .ja v a 2 s .co m*/ */ public static ScratchVersion fromJSON(String json) { JSONObject jObj = (JSONObject) JSONValue.parse(json); boolean dirty = ((Boolean) jObj.get("dirty") != null) ? ((Boolean) jObj.get("dirty")) : false; Date saveTime = toDate((String) jObj.get(JSONKeys.TIME)); String longName = (String) jObj.get(JSONKeys.LONGNAME); ScratchVersion sv = new ScratchVersion((String) jObj.get(JSONKeys.VERSION1), longName, (String) jObj.get(JSONKeys.DOCID), (String) jObj.get(JSONKeys.DBASE), saveTime, dirty); JSONArray jArr = (JSONArray) jObj.get("layers"); if (jArr != null) { for (int i = 0; i < jArr.size(); i++) { JSONObject jLayer = (JSONObject) jArr.get(i); String layerName = (String) jLayer.get(JSONKeys.NAME); String body = (String) jLayer.get(JSONKeys.BODY); int layerNum = layerNumber(layerName); sv.addLayer(body.toCharArray(), layerNum); } } return sv; }
From source file:com.serena.rlc.provider.jira.domain.Issue.java
public static Issue parseSingle(JSONObject jsonObject) { Issue obj = new Issue(); if (jsonObject != null) { 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")); }//www . ja v a2 s.c o m return obj; }
From source file:com.jts.rest.profileservice.utils.RestServiceHelper.java
/** * Uses MemberChallenge service to get all the associated challenge information for a user * Sorts the challenge information with end date * Returns all the active challenges and 3 most recent past challenge * @param sessionId//from w w w . j ava 2s. co m * @param username * @return * @throws MalformedURLException * @throws IOException */ @SuppressWarnings("unchecked") public static JSONObject getProcessedChallengesM1(String sessionId, String username) throws MalformedURLException, IOException { //get all challenges JSONArray challenges = getChallenges(sessionId, username); JSONArray activeChallenges = new JSONArray(); JSONArray pastChallenges = new JSONArray(); SortedMap<Long, JSONObject> pastChallengesByDate = new TreeMap<Long, JSONObject>(); Iterator<JSONObject> iterator = challenges.iterator(); DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-ddhh:mm:ss"); while (iterator.hasNext()) { JSONObject challenge = iterator.next(); //identify active challenge with status if (challenge.get("Status__c").equals(PSContants.STATUS_CREATED)) { activeChallenges.add(challenge); } else { String endDateStr = ((String) challenge.get("End_Date__c")).replace("T", ""); Date date = new Date(); try { date = dateFormat.parse(endDateStr); } catch (ParseException pe) { logger.log(Level.SEVERE, "Error occurent while parsing date " + endDateStr); } pastChallengesByDate.put(date.getTime(), challenge); } } //from the sorted map extract the recent challenge int pastChallengeSize = pastChallengesByDate.size(); if (pastChallengeSize > 0) { Object[] challengeArr = (Object[]) pastChallengesByDate.values().toArray(); int startIndex = pastChallengeSize > 3 ? pastChallengeSize - 3 : 0; for (int i = startIndex; i < pastChallengeSize; i++) { pastChallenges.add(challengeArr[i]); } } JSONObject resultChallenges = new JSONObject(); resultChallenges.put("activeChallenges", activeChallenges); resultChallenges.put("pastChallenges", pastChallenges); resultChallenges.put("totalChallenges", challenges.size()); return resultChallenges; }
From source file:compare.handler.CompareHandler.java
/** * Get the document body of the given urn or null * @param db the database where it is// w ww . j a v a 2s .c o m * @param docID the docID of the resource * @return the document body or null if not present */ private static String getDocumentBody(String db, String docID) throws CompareException { try { String jStr = Connector.getConnection().getFromDb(db, docID); if (jStr != null) { JSONObject jDoc = (JSONObject) JSONValue.parse(jStr); if (jDoc != null) { String body = (String) jDoc.get(JSONKeys.BODY); if (body != null) return body; } } throw new CompareException("document " + db + "/" + docID + " not found"); } catch (Exception e) { throw new CompareException(e); } }
From source file:com.apigee.edge.config.mavenplugin.TargetServerMojo.java
public static List getTarget(ServerProfile profile) throws IOException { HttpResponse response = RestUtil.getEnvConfig(profile, "targetservers"); if (response == null) return new ArrayList(); JSONArray targets = null;/*from w ww. j ava2s .co m*/ try { logger.debug("output " + response.getContentType()); // response can be read only once String payload = response.parseAsString(); logger.debug(payload); /* Parsers fail to parse a string array. * converting it to an JSON object as a workaround */ String obj = "{ \"targets\": " + payload + "}"; JSONParser parser = new JSONParser(); JSONObject obj1 = (JSONObject) parser.parse(obj); targets = (JSONArray) obj1.get("targets"); } catch (ParseException pe) { logger.error("Get Target Server parse error " + pe.getMessage()); throw new IOException(pe.getMessage()); } catch (HttpResponseException e) { logger.error("Get Target Server error " + e.getMessage()); throw new IOException(e.getMessage()); } return targets; }
From source file:com.criticalsoftware.mobics.presentation.util.GeolocationUtil.java
private static String getFormattedAddress(JSONObject jsonObject) { String result = null;/* ww w . jav a 2 s . com*/ if (jsonObject != null && jsonObject.containsKey("address")) { result = ""; JSONObject address = (JSONObject) jsonObject.get("address"); if (address.containsKey("road")) { result += address.get("road").toString(); } if (result.isEmpty() && address.containsKey("path")) { result += address.get("path").toString(); } if (result.isEmpty() && address.containsKey("cycleway")) { result += address.get("cycleway").toString(); } if (address.containsKey("house_number")) { if (result.isEmpty() == false) { result += " "; } result += address.get("house_number").toString(); } } return result; }