public int getRequestFrequency(String path) { if (!this.json.has("frequency")) return -1; JSONObject paths = this.json.getJSONObject("frequency"); if (!paths.has(path)) return -1; return paths.getInt(path); }
private void transformCardCellData(JSONObject cardData) { try { if (cardData.has("iconList")) { cardData.put(Card.KEY_ITEMS, cardData.getJSONArray("iconList")); } else if (cardData.has("centerBannerList")) { cardData.put(Card.KEY_ITEMS, cardData.getJSONArray("centerBannerList")); } } catch (JSONException e) { e.printStackTrace(); } }
private List<JSONObject> getSubAlbumJSONs(JSONObject data) { List<JSONObject> subalbumJSONs = new ArrayList<>(); if (data.has("subAlbums")) { JSONArray subalbums = data.getJSONArray("subAlbums"); for (int idx = 0; idx < subalbums.length(); idx++) { JSONObject subalbumJSON = subalbums.getJSONObject(idx); subalbumJSONs.add(subalbumJSON); } } return subalbumJSONs; } }
public void setPermission(String servletCanonicalName, String key, String value){ if(!permissions.has(servletCanonicalName)) permissions.put(servletCanonicalName, new JSONObject()); permissions.getJSONObject(servletCanonicalName).put(key, value); }
JSONObject appLinkArgsJson = new JSONObject(jsonString); String version = appLinkArgsJson.getString(APPLINK_VERSION_KEY); appLinkData.arguments = appLinkArgsJson.getJSONObject(APPLINK_METHOD_ARGS_KEY); if (appLinkData.arguments.has(METHOD_ARGS_REF_KEY)) { appLinkData.ref = appLinkData.arguments.getString(METHOD_ARGS_REF_KEY); } else if (appLinkData.arguments.has(ARGUMENTS_REFERER_DATA_KEY)) { JSONObject refererData = appLinkData.arguments.getJSONObject( ARGUMENTS_REFERER_DATA_KEY); if (refererData.has(REFERER_DATA_REF_KEY)) { appLinkData.ref = refererData.getString(REFERER_DATA_REF_KEY); if (appLinkData.arguments.has(METHOD_ARGS_TARGET_URL_KEY)) { appLinkData.targetUri = Uri.parse( appLinkData.arguments.getString(METHOD_ARGS_TARGET_URL_KEY)); if (appLinkData.arguments.has(ARGUMENTS_EXTRAS_KEY)) { JSONObject extrasData = appLinkData.arguments.getJSONObject(ARGUMENTS_EXTRAS_KEY); if (extrasData.has(EXTRAS_DEEPLINK_CONTEXT_KEY)) { JSONObject deeplink_context = extrasData.getJSONObject(EXTRAS_DEEPLINK_CONTEXT_KEY); if (deeplink_context.has(PROMOTION_CODE_KEY)) { appLinkData.promotionCode = deeplink_context.getString(PROMOTION_CODE_KEY);
public static Message toObject(String jsonStr) { Message m = new Message(); try { JSONObject jsonObject = new JSONObject(jsonStr); m.setHandlerName(jsonObject.has(HANDLER_NAME_STR) ? jsonObject.getString(HANDLER_NAME_STR):null); m.setCallbackId(jsonObject.has(CALLBACK_ID_STR) ? jsonObject.getString(CALLBACK_ID_STR):null); m.setResponseData(jsonObject.has(RESPONSE_DATA_STR) ? jsonObject.getString(RESPONSE_DATA_STR):null); m.setResponseId(jsonObject.has(RESPONSE_ID_STR) ? jsonObject.getString(RESPONSE_ID_STR):null); m.setData(jsonObject.has(DATA_STR) ? jsonObject.getString(DATA_STR):null); return m; } catch (JSONException e) { e.printStackTrace(); } return m; }
/** * If during thinking we observe something that we want to memorize, we can memorize this here * @param featureName the object key * @param observation the object value * @return the thought */ public SusiThought addObservation(String featureName, String observation) { JSONArray data = getData(); for (int i = 0; i < data.length(); i++) { JSONObject spark = data.getJSONObject(i); if (!spark.has(featureName)) { spark.put(featureName, observation); return this; } } data.put(new JSONObject().put(featureName, observation)); return this; }
private Post jsonToPost(JSONObject post) throws JSONException { String message = null; if (post.has("message")) { message = post.getString("message"); } String picture = null; if (post.has("picture")) { picture = post.getString("picture"); } String created_time = post.getString("created_time"); String id = post.getString("id"); JSONObject from = post.getJSONObject("from"); String from_name = from.getString("name"); String from_id = from.getString("id"); return new Post(message, created_time, id, picture, from_name, from_id); }
/** * All details of the creation of this thought is collected in a metadata statement. * @return the set of meta information for this thought */ private JSONObject getMetadata() { JSONObject md; if (this.has(metadata_name)) md = this.getJSONObject(metadata_name); else { md = new JSONObject(); this.put(metadata_name, md); } if (!md.has("count")) md.put("count", getData().length()); return md; }
private void handleRemoteMessage(JsonRpcPeer peer, String message) throws IOException, MessageHandlingException, JSONException { // Parse as a generic JSONObject first since we don't know if this is a request or response. JSONObject messageNode = new JSONObject(message); if (messageNode.has("method")) { handleRemoteRequest(peer, messageNode); } else if (messageNode.has("result")) { handleRemoteResponse(peer, messageNode); } else { throw new MessageHandlingException("Improper JSON-RPC message: " + message); } }
public static TwitterTimeline peers(final String protocolhostportstub, final String query, final TwitterTimeline.Order order, final String source, final int count, final int timezoneOffset, final String provider_hash) throws IOException { TwitterTimeline tl = new TwitterTimeline(order); String urlstring = ""; urlstring = protocolhostportstub + "/api/peers.json"; byte[] response = ClientConnection.download(urlstring); if (response == null || response.length == 0) return tl; JSONObject json = new JSONObject(new String(response, StandardCharsets.UTF_8)); JSONArray statuses = json.has("statuses") ? json.getJSONArray("statuses") : null; if (statuses != null) { for (Object tweet_obj: statuses) { JSONObject tweet = (JSONObject) tweet_obj; JSONObject user = tweet.has("user") ? (JSONObject) tweet.remove("user") : null; if (user == null) continue; tweet.put("provider_type", (Object) ProviderType.REMOTE.name()); tweet.put("provider_hash", provider_hash); UserEntry u = new UserEntry(user); TwitterTweet t = new TwitterTweet(tweet); tl.add(t, u); } } //System.out.println(parser.text()); return tl; }
protected static Emoji buildEmojiFromJSON( JSONObject json ) throws UnsupportedEncodingException { if (!json.has("emoji")) { return null; } byte[] bytes = json.getString("emoji").getBytes("UTF-8"); String description = null; if (json.has("description")) { description = json.getString("description"); } boolean supportsFitzpatrick = false; if (json.has("supports_fitzpatrick")) { supportsFitzpatrick = json.getBoolean("supports_fitzpatrick"); } List<String> aliases = jsonArrayToStringList(json.getJSONArray("aliases")); List<String> tags = jsonArrayToStringList(json.getJSONArray("tags")); return new Emoji(description, supportsFitzpatrick, aliases, tags, bytes); }
public List<String> getArrayValues(String key) { List<String> result = new ArrayList<>(); if (jsonObject.has(key)) { JSONArray jsonArray = jsonObject.getJSONArray(key); for (int i = 0; i < jsonArray.length(); i++) { result.add(jsonArray.getString(i)); } } return result; }
/** * create a clone of a json object as a SusiThought object * @param json the 'other' thought, probably an exported and re-imported thought */ public SusiThought(JSONObject json) { this(); if (json.has(this.metadata_name)) this.put(this.metadata_name, json.getJSONObject(this.metadata_name)); if (json.has(this.data_name)) this.setData(json.getJSONArray(this.data_name)); if (json.has("actions")) this.put("actions", json.getJSONArray("actions")); }
public static CurrentPlaceResult fromJson(JSONObject json) throws JSONException { CurrentPlaceResult response = new CurrentPlaceResult(); if (json.has(PARAM_DATA)) { JSONArray array = json.getJSONArray(PARAM_DATA); int length = array.length(); response.places = new ArrayList<>(length); for (int i=0; i<length; i++) { JSONObject placeJson = array.getJSONObject(i); response.places.add(new Place(placeJson)); } } if (json.has(PARAM_SUMMARY)) { JSONObject summaryJson = json.getJSONObject(PARAM_SUMMARY); response.tracking = summaryJson.getString(PARAM_TRACKING); } return response; } }
public void setPermission(String servletCanonicalName, String key, long value){ if(!permissions.has(servletCanonicalName)) permissions.put(servletCanonicalName, new JSONObject()); permissions.getJSONObject(servletCanonicalName).put(key, value); }
@Override public void rip() throws IOException { LOGGER.info("Retrieving " + this.url); String html = Http.url(url).get().html(); String jsonString = html.substring(html.indexOf("var flashVars = {d: '") + 21); jsonString = jsonString.substring(0, jsonString.indexOf("'")); JSONObject json = new JSONObject(new String(Base64.decode(jsonString))); JSONObject jsonURL = new JSONObject(new String(Base64.decode(json.getString("url")))); String encryptedURL = jsonURL.getJSONObject("u").getString("l"); String vidURL = ""; for (char c : encryptedURL.toCharArray()) { if (decryptDict.has(Character.toString(c))) { vidURL += decryptDict.getString(Character.toString(c)); } else { vidURL += c; } } addURLToDownload(new URL(vidURL), HOST + "_" + getGID(this.url)); waitForThreads(); } }
private static JSONObject formatHeadersAsJSON(InspectorHeaders headers) { JSONObject json = new JSONObject(); for (int i = 0; i < headers.headerCount(); i++) { String name = headers.headerName(i); String value = headers.headerValue(i); try { if (json.has(name)) { // Multiple headers are separated with a new line. json.put(name, json.getString(name) + "\n" + value); } else { json.put(name, value); } } catch (JSONException e) { throw new RuntimeException(e); } } return json; }