/** * Get extra JSONObject value. * @param key The key of the stored value. * @return The stored value or null if it doesn't exist in specified form. */ public JSONObject optExtraJSONObject(String key) { return mExtraData.optJSONObject(key); }
/** * Get extra JSONObject value. * @param key The key of the stored value. * @return The stored value or null if it doesn't exist in specified form. */ public JSONObject optExtraJSONObject(String key) { return mExtraData.optJSONObject(key); }
public JSONObject getJson(String field) { return jsonData.optJSONObject(field); }
public static JSONObject tryGetJSONObjectFromResponse(JSONObject response, String propertyKey) { return response != null ? response.optJSONObject(propertyKey) : null; }
public JSONObject optJsonObjectParam(String key) { if (extras.has(key)) return extras.optJSONObject(key); if (style != null && style.extras != null) return style.extras.optJSONObject(key); return null; }
public JSONObject optJsonObjectParam(String key) { if (extras.has(key)) { return extras.optJSONObject(key); } if (style != null && style.extras != null) { return style.extras.optJSONObject(key); } return null; }
public String getCoverPhotoUrl() { JSONObject coverPhotoJson = jsonData.optJSONObject("cover"); if (coverPhotoJson != null) { return coverPhotoJson.optString("source"); } return null; }
protected Uri getPictureUriOfGraphObject(JSONObject graphObject) { String uri = null; Object o = graphObject.opt(PICTURE); if (o instanceof String) { uri = (String) o; } else if (o instanceof JSONObject) { JSONObject data = ((JSONObject) o).optJSONObject("data"); uri = data != null ? data.optString("url") : null; } if (uri != null) { return Uri.parse(uri); } return null; }
/** * Populate a UrlDevice with data from a given JSON object. * @param jsonObject a serialized UrlDevice. * @return The UrlDevice represented by the serialized object. */ public static UrlDevice jsonDeserialize(JSONObject jsonObject) { return new Builder(jsonObject.getString(ID_KEY), jsonObject.getString(URL_KEY)) .setExtra(jsonObject.optJSONObject(EXTRA_KEY)) .build(); }
@Override protected void processSuccess(GraphResponse response) { JSONObject results = Utility.tryGetJSONObjectFromResponse( response.getJSONObject(), objectId); if (results != null) { // See if we can get the OG object Id out JSONObject ogObject = results.optJSONObject("og_object"); if (ogObject != null) { verifiedObjectId = ogObject.optString("id"); } } } }
public LatLng getPosition() { JSONObject location = jsonData.optJSONObject(LOCATION); if (location != null) { if (location.has("latitude") && location.has("longitude")) { double latitude = location.optDouble("latitude"); double longitude = location.optDouble("longitude"); return new LatLng(latitude, longitude); } } return null; }
public List<AppLink> getAppLinks() { List<AppLink> appLinks = new ArrayList<>(); JSONObject appLinkJson = jsonData.optJSONObject(APP_LINKS); if (appLinkJson != null) { JSONArray appArray = appLinkJson.optJSONArray("android"); if (appArray != null) { int length = appArray.length(); for (int i = 0; i < length; i++) { JSONObject linkJson = appArray.optJSONObject(i); if (linkJson != null) { String appName = linkJson.optString("app_name"); Intent intent = new Intent(Intent.ACTION_VIEW); String packageName = linkJson.optString("package"); String className = linkJson.optString("class"); if (!TextUtils.isEmpty(packageName) && !TextUtils.isEmpty(className)) { intent.setClassName(packageName, className); } String url = linkJson.optString("url"); if (url != null) { intent.setData(Uri.parse(url)); } appLinks.add(new AppLink(appName, intent)); } } } } return appLinks; }
@Override public void parseWith(@NonNull JSONObject data, @NonNull MVHelper resolver) { maxChildren = 1; this.extras = data; this.stringType = data.optString(KEY_TYPE); id = data.optString(KEY_ID, id == null ? "" : id); loadMore = data.optInt(KEY_LOAD_TYPE, 0) == LOAD_TYPE_LOADMORE; //you should alway assign hasMore to indicate there's more data explicitly if (data.has(KEY_HAS_MORE)) { hasMore = data.optBoolean(KEY_HAS_MORE); } else { if (data.has(KEY_LOAD_TYPE)) { hasMore = data.optInt(KEY_LOAD_TYPE) == LOAD_TYPE_LOADMORE; } } load = data.optString(KEY_API_LOAD, null); loadParams = data.optJSONObject(KEY_API_LOAD_PARAMS); loaded = data.optBoolean(KEY_LOADED, false); createCell(this, resolver, extras, serviceManager, true); //do not need parse style, leave style empty this.extras.remove(KEY_STYLE); style = new Style(); }
/** * Populate a PwsResult with data from a given JSON object. * @param jsonObject a serialized PwsResult. * @return The PwsResult represented by the serialized object. */ public static PwsResult jsonDeserialize(JSONObject jsonObject) { return new Builder(jsonObject.getString(REQUESTURL_KEY), jsonObject.getString(SITEURL_KEY)) .setExtra(jsonObject.optJSONObject(EXTRA_KEY)) .setTitle(jsonObject.optString(TITLE_KEY)) .setDescription(jsonObject.optString(DESCRIPTION_KEY)) .setIconUrl(jsonObject.optString(ICONURL_KEY)) .setGroupId(jsonObject.optString(GROUPID_KEY)) .build(); } }
protected void parseCell(MVHelper resolver, BaseCell cell, JSONObject json) { if (json != null) { cell.extras = json; cell.id = json.optString(KEY_BIZ_ID); if (TextUtils.isEmpty(cell.id) && json.has(KEY_ID)) { cell.id = json.optString(KEY_ID); } cell.type = json.optInt(KEY_TYPE); cell.stringType = json.optString(KEY_TYPE); cell.typeKey = json.optString(KEY_TYPE_KEY); String reuseId = json.optString(KEY_TYPE_REUSEID); if (!TextUtils.isEmpty(reuseId)) { cell.typeKey = reuseId; } cell.position = json.optInt(KEY_POSITION, -1); parseBizParams(cell, json); cell.parseWith(json); cell.parseWith(json, resolver); JSONObject styleJson = json.optJSONObject(KEY_STYLE); parseStyle(cell, styleJson); parseBizParams(cell, styleJson); } else { cell.extras = new JSONObject(); } }
JSONObject dia = jo.optJSONObject("dialog");
private synchronized void populateTestAccounts(JSONArray testAccounts, JSONObject userAccountsMap) { for (int i = 0; i < testAccounts.length(); ++i) { JSONObject testAccount = testAccounts.optJSONObject(i); JSONObject testUser = userAccountsMap.optJSONObject(testAccount.optString("id")); try { testAccount.put("name", testUser.optString("name")); } catch (JSONException e) { Log.e(LOG_TAG, "Could not set name", e); } storeTestAccount(testAccount); } }
@Override public void onRemoveSearch(String searchName) { Timber.d("OnRemoveSelection using search named: %s", searchName); try { JSONObject savedFiltersObj = getCol().getConf().optJSONObject("savedFilters"); if (savedFiltersObj != null && savedFiltersObj.has(searchName)) { savedFiltersObj.remove(searchName); getCol().getConf().put("savedFilters", savedFiltersObj); getCol().flush(); if (savedFiltersObj.length() == 0) { mMySearchesItem.setVisible(false); } } } catch (JSONException e) { throw new RuntimeException(e); } }
@Override public void onSelection(String searchName) { Timber.d("OnSelection using search named: %s", searchName); JSONObject savedFiltersObj = getCol().getConf().optJSONObject("savedFilters"); Timber.d("SavedFilters are %s", savedFiltersObj.toString()); if (savedFiltersObj != null) { mSearchTerms = savedFiltersObj.optString(searchName); Timber.d("OnSelection using search terms: %s", mSearchTerms); mSearchView.setQuery(mSearchTerms, false); mSearchItem.expandActionView(); searchCards(); } }
@Override protected void processSuccess(GraphResponse response) { JSONArray dataSet = Utility.tryGetJSONArrayFromResponse( response.getJSONObject(), "data"); if (dataSet != null) { for (int i = 0; i < dataSet.length(); i++) { JSONObject data = dataSet.optJSONObject(i); if (data != null) { objectIsLiked = true; JSONObject appData = data.optJSONObject("application"); AccessToken accessToken = AccessToken.getCurrentAccessToken(); if (appData != null && AccessToken.isCurrentAccessTokenActive() && Utility.areObjectsEqual( accessToken.getApplicationId(), appData.optString("id"))) { unlikeToken = data.optString("id"); } } } } }