List of usage examples for org.json.simple JSONObject get
V get(Object key);
From source file:me.ryandowling.allmightybot.utils.TwitchAPI.java
public static String getTopic(String username) throws IOException, ParseException { TwitchAPIRequest request = new TwitchAPIRequest("/channels/" + username); String response = request.get(); JSONParser parser = new JSONParser(); JSONObject jsonObject = (JSONObject) parser.parse(response); return (String) jsonObject.get("status"); }
From source file:me.ryandowling.allmightybot.utils.TwitchAPI.java
public static String setTopic(String username, String topic) throws IOException, ParseException { TwitchAPIRequest request = new TwitchAPIRequest("/channels/" + username); String response = request.put(new ChannelPutRequest(topic)); JSONParser parser = new JSONParser(); JSONObject jsonObject = (JSONObject) parser.parse(response); return (String) jsonObject.get("status"); }
From source file:com.wso2.raspberrypi.apicalls.APICall.java
/** * Populates Token object using folloing JSON String * {/* ww w .j a va 2 s . co m*/ * "token_type": "bearer", * "expires_in": 3600000, * "refresh_token": "f43de118a489d56c3b3b7ba77a1549e", * "access_token": "269becaec9b8b292906b3f9e69b5a9" * } * * @param accessTokenJson * @return */ public static Token getAccessToken(String accessTokenJson) { JSONParser parser = new JSONParser(); Token token = new Token(); try { Object obj = parser.parse(accessTokenJson); JSONObject jsonObject = (JSONObject) obj; token.setAccessToken((String) jsonObject.get("access_token")); long expiresIn = ((Long) jsonObject.get("expires_in")).intValue(); token.setExpiresIn(expiresIn); token.setRefreshToken((String) jsonObject.get("refresh_token")); token.setTokenType((String) jsonObject.get("token_type")); } catch (ParseException e) { log.error("", e); } return token; }
From source file:bhl.pages.handler.PagesGetHandler.java
protected static void sortList(JSONArray a) { int increment = a.size() / 2; while (increment > 0) { for (int i = increment; i < a.size(); i++) { int j = i; JSONObject temp = (JSONObject) a.get(i); int tempN = ((Number) temp.get("n")).intValue(); JSONObject aObj = ((JSONObject) a.get(j - increment)); int aN = ((Number) aObj.get("n")).intValue(); while (j >= increment && aN > tempN) { a.set(j, a.get(j - increment)); j = j - increment;/* w w w .ja va2 s.co m*/ if (j >= increment) { aObj = ((JSONObject) a.get(j - increment)); aN = ((Number) aObj.get("n")).intValue(); } } a.set(j, temp); } if (increment == 2) { increment = 1; } else { increment *= (5.0 / 11); } } }
From source file:biomine.bmvis2.pipeline.GraphOperationSerializer.java
private static Map<String, Double> getNodesOfInterest(JSONArray arr) { Map<String, Double> ret = new HashMap(); for (Object o : arr) { if (o instanceof JSONArray) { JSONArray a = (JSONArray) o; for (Object ao : a) { JSONObject jo = (JSONObject) ao; ret.put(jo.get("node").toString(), (Double) jo.get("value")); }/*from w ww. jav a2 s . co m*/ } } return ret; }
From source file:myproject.MyServer.java
public static void Query(HttpServletRequest request, HttpServletResponse response) throws IOException { try {// w w w . j av a 2s. co m String jsonString = IOUtils.toString(request.getInputStream()); JSONObject json = (JSONObject) JSONValue.parse(jsonString); String query = (String) json.get("query"); String result = database.runQuery(query); response.getWriter().write(result); } catch (Exception ex) { JSONObject output = new JSONObject(); output.put("error", "Connection failed: " + ex.getMessage()); response.getWriter().write(JSONValue.toJSONString(output)); } }
From source file:com.modeln.batam.connector.wrapper.Commit.java
public static Commit fromJSON(JSONObject obj) { String buildId = (String) obj.get("build_id"); String buildName = (String) obj.get("build_name"); String commitId = (String) obj.get("commit_id"); String url = (String) obj.get("url"); String author = (String) obj.get("author"); String dateCommitted = (String) obj.get("date_committed"); DateFormat dateFormat = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy Z"); try {/*w w w . ja v a2 s.c o m*/ return new Commit(buildId, buildName, commitId, url, author, dateCommitted == null ? null : dateFormat.parse(dateCommitted)); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:com.serena.rlc.provider.jira.domain.Project.java
public static Project parseSingle(JSONObject jsonObject) { Project obj = new Project(); if (jsonObject != null) { obj.setId((String) jsonObject.get("id")); obj.setName((String) jsonObject.get("name")); obj.setKey((String) jsonObject.get("key")); }//from www .jav a 2 s. c o m return obj; }
From source file:eu.hansolo.tilesfx.weather.Sun.java
private static ZonedDateTime[] parseJsonData(final String JSON_DATA, final ZoneId ZONE_ID) { Object obj = JSONValue.parse(JSON_DATA); JSONObject jsonObj = (JSONObject) obj; // Results// w ww. j a v a2 s . c om JSONObject results = (JSONObject) jsonObj.get("results"); LocalDateTime sunrise = LocalDateTime.parse(results.get("sunrise").toString(), DateTimeFormatter.ISO_DATE_TIME); LocalDateTime sunset = LocalDateTime.parse(results.get("sunset").toString(), DateTimeFormatter.ISO_DATE_TIME); /* LocalDateTime solarNoon = LocalDateTime.parse(results.get("solar_noon").toString(), DateTimeFormatter.ISO_DATE_TIME); LocalDateTime dayLength = LocalDateTime.parse(results.get("day_length").toString(), DateTimeFormatter.ISO_DATE_TIME); LocalDateTime civilTwilightBegin = LocalDateTime.parse(results.get("civil_twilight_begin").toString(), DateTimeFormatter.ISO_DATE_TIME); LocalDateTime nauticalTwilightBegin = LocalDateTime.parse(results.get("nautical_twilight_begin").toString(), DateTimeFormatter.ISO_DATE_TIME); LocalDateTime nauticalTwilightEnd = LocalDateTime.parse(results.get("nautical_twilight_end").toString(), DateTimeFormatter.ISO_DATE_TIME); LocalDateTime astronomicalTwilightBegin = LocalDateTime.parse(results.get("astronomical_twilight_begin").toString(), DateTimeFormatter.ISO_DATE_TIME); LocalDateTime astronomicalTwilightEnd = LocalDateTime.parse(results.get("astronomical_twilight_end").toString(), DateTimeFormatter.ISO_DATE_TIME); */ return new ZonedDateTime[] { ZonedDateTime.of(sunrise, ZONE_ID), ZonedDateTime.of(sunset, ZONE_ID) }; }
From source file:ly.stealth.punxsutawney.Marathon.java
private static JSONArray getTasks(String app) throws IOException { JSONObject app_ = getApp(app); return app_ != null ? (JSONArray) app_.get("tasks") : null; }