List of usage examples for org.json JSONObject optString
public String optString(String key)
From source file:com.google.blockly.model.FieldInput.java
public static FieldInput fromJson(JSONObject json) throws BlockLoadingException { String name = json.optString("name"); if (TextUtils.isEmpty(name)) { throw new BlockLoadingException("field_input \"name\" attribute must not be empty."); }//from w w w . ja va 2 s . co m // TODO: consider replacing default text with string resource return new FieldInput(name, json.optString("text", "default")); }
From source file:com.vk.sdkweb.api.model.VKApiVideo.java
/** * Fills a Video instance from JSONObject. *///from www. j a v a 2s . c o m public VKApiVideo parse(JSONObject from) { id = from.optInt("id"); owner_id = from.optInt("owner_id"); title = from.optString("title"); description = from.optString("description"); duration = from.optInt("duration"); link = from.optString("link"); date = from.optLong("date"); views = from.optInt("views"); comments = from.optInt("comments"); player = from.optString("player"); access_key = from.optString("access_key"); album_id = from.optInt("album_id"); JSONObject likes = from.optJSONObject("likes"); if (likes != null) { this.likes = likes.optInt("count"); user_likes = parseBoolean(likes, "user_likes"); } can_comment = parseBoolean(from, "can_comment"); can_repost = parseBoolean(from, "can_repost"); repeat = parseBoolean(from, "repeat"); privacy_view = VKPrivacy.parsePrivacy(from.optJSONObject("privacy_view")); privacy_comment = VKPrivacy.parsePrivacy(from.optJSONObject("privacy_comment")); JSONObject files = from.optJSONObject("files"); if (files != null) { mp4_240 = files.optString("mp4_240"); mp4_360 = files.optString("mp4_360"); mp4_480 = files.optString("mp4_480"); mp4_720 = files.optString("mp4_720"); external = files.optString("external"); } photo_130 = from.optString("photo_130"); if (!TextUtils.isEmpty(photo_130)) { photo.add(VKApiPhotoSize.create(photo_130, 130)); } photo_320 = from.optString("photo_320"); if (!TextUtils.isEmpty(photo_320)) { photo.add(VKApiPhotoSize.create(photo_320, 320)); } photo_640 = from.optString("photo_640"); if (!TextUtils.isEmpty(photo_640)) { photo.add(VKApiPhotoSize.create(photo_640, 640)); } return this; }
From source file:com.rjfun.cordova.qq.QQPlugin.java
public void setOptions(JSONObject options) { Log.d(LOGTAG, "setOptions"); if (options != null) { if (options.has(OPT_IS_TESTING)) this.isTesting = options.optBoolean(OPT_IS_TESTING); if (options.has(OPT_LOG_VERBOSE)) this.logVerbose = options.optBoolean(OPT_LOG_VERBOSE); if (options.has(OPT_APPID)) this.appId = options.optString(OPT_APPID); if (options.has(OPT_APPKEY)) this.appKey = options.optString(OPT_APPKEY); if (options.has(OPT_APPNAME)) this.appName = options.optString(OPT_APPNAME); }/*from ww w . j a va2s . co m*/ }
From source file:com.rjfun.cordova.qq.QQPlugin.java
public boolean share(JSONObject args) { Log.d(LOGTAG, "share"); if (!this.inited) { this.mTencent = Tencent.createInstance(this.appId, this.getActivity().getApplicationContext()); this.inited = true; }//from w ww . j av a 2 s .c om String message = args.optString(OPT_MESSAGE); String subject = args.optString(OPT_SUBJECT); String image = args.optString(OPT_IMAGE); String url = args.optString(OPT_URL); final boolean qqZone = args.optBoolean(OPT_QQZONE); final Bundle params = new Bundle(); if (qqZone) { params.putInt(QzoneShare.SHARE_TO_QZONE_KEY_TYPE, QzoneShare.SHARE_TO_QZONE_TYPE_IMAGE_TEXT); params.putString(QzoneShare.SHARE_TO_QQ_TITLE, subject); params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, message); params.putString(QzoneShare.SHARE_TO_QQ_TARGET_URL, url); ArrayList<String> images = new ArrayList<String>(); images.add(image); params.putStringArrayList(QQShare.SHARE_TO_QQ_IMAGE_URL, images); params.putString(QzoneShare.SHARE_TO_QQ_APP_NAME, this.appName + "" + this.appId); } else { params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT); params.putString(QQShare.SHARE_TO_QQ_TITLE, subject); params.putString(QQShare.SHARE_TO_QQ_SUMMARY, message); params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, url); params.putString(QzoneShare.SHARE_TO_QQ_IMAGE_URL, image); params.putString(QQShare.SHARE_TO_QQ_APP_NAME, this.appName + "" + this.appId); //params.putInt(QQShare.SHARE_TO_QQ_EXT_INT, 0); } final Activity activity = this.getActivity(); final IUiListener qqDelegate = this; activity.runOnUiThread(new Runnable() { @Override public void run() { if (qqZone) { mTencent.shareToQzone(activity, params, qqDelegate); } else { mTencent.shareToQQ(activity, params, qqDelegate); } } }); return true; }
From source file:de.hscoburg.etif.vbis.lagerix.android.barcode.result.supplement.BookResultInfoRetriever.java
@Override void retrieveSupplementalInfo() throws IOException { CharSequence contents = HttpHelper.downloadViaHttp( "https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn, HttpHelper.ContentType.JSON); if (contents.length() == 0) { return;/*from ww w . j a v a2s .c o m*/ } String title; String pages; Collection<String> authors = null; try { JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue(); JSONArray items = topLevel.optJSONArray("items"); if (items == null || items.isNull(0)) { return; } JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo"); if (volumeInfo == null) { return; } title = volumeInfo.optString("title"); pages = volumeInfo.optString("pageCount"); JSONArray authorsArray = volumeInfo.optJSONArray("authors"); if (authorsArray != null && !authorsArray.isNull(0)) { authors = new ArrayList<String>(authorsArray.length()); for (int i = 0; i < authorsArray.length(); i++) { authors.add(authorsArray.getString(i)); } } } catch (JSONException e) { throw new IOException(e.toString()); } Collection<String> newTexts = new ArrayList<String>(); maybeAddText(title, newTexts); maybeAddTextSeries(authors, newTexts); maybeAddText(pages == null || pages.length() == 0 ? null : pages + "pp.", newTexts); String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context) + "/search?tbm=bks&source=zxing&q="; append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn); }
From source file:com.company.project.core.connector.HttpClientHelper.java
/** * for good response/* www. ja va 2 s . c o m*/ * * @param responseCode * @param responseMsg * @return * @throws JSONException */ public static JSONObject processBadRespStr(int responseCode, String responseMsg) throws JSONException { JSONObject response = new JSONObject(); response.put("responseCode", responseCode); if (responseMsg.equalsIgnoreCase("")) { // good response is empty string response.put("responseMsg", ""); } else { // bad response is json string JSONObject errorObject = new JSONObject(responseMsg).optJSONObject("odata.error"); String errorCode = errorObject.optString("code"); String errorMsg = errorObject.optJSONObject("message").optString("value"); response.put("responseCode", responseCode); response.put("errorCode", errorCode); response.put("errorMsg", errorMsg); } return response; }
From source file:com.commonsware.empub.BookContents.java
String getChapterFile(int position) { JSONObject chapter = chapters.optJSONObject(position); return (chapter.optString("file")); }
From source file:com.commonsware.empub.BookContents.java
String getChapterTitle(int position) { JSONObject chapter = chapters.optJSONObject(position); String result = chapter.optString("title"); if (result == null) { result = String.valueOf(position + 1); }/* w ww . j a v a 2 s . c om*/ return (result); }
From source file:com.fuse.billing.android.SkuDetails.java
public SkuDetails(JSONObject o) { mJson = o;//from w w w.jav a 2 s. c o m mSku = o.optString("productId"); mType = o.optString("type"); mPrice = o.optString("price"); mPriceAmountMicros = o.optLong("price_amount_micros"); mPriceCurrencyCode = o.optString("price_currency_code"); mTitle = o.optString("title"); mDescription = o.optString("description"); }
From source file:net.digitalphantom.app.weatherapp.data.Units.java
@Override public void populate(JSONObject data) { temperature = data.optString("temperature"); }