Java Code Examples for org.json.JSONObject.optString()

The following are Jave code examples for showing how to use optString() of the org.json.JSONObject class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: QianXun   File: Geo.java   View Source Code Vote up 8 votes
public static Geo parse(JSONObject jsonObject) {
    if (null == jsonObject) {
        return null;
    }
    
    Geo geo = new Geo();
    geo.longitude       = jsonObject.optString("longitude");
    geo.latitude        = jsonObject.optString("latitude");
    geo.city            = jsonObject.optString("city");
    geo.province        = jsonObject.optString("province");
    geo.city_name       = jsonObject.optString("city_name");
    geo.province_name   = jsonObject.optString("province_name");
    geo.address         = jsonObject.optString("address");
    geo.pinyin          = jsonObject.optString("pinyin");
    geo.more            = jsonObject.optString("more");
    
    return geo;
}
 
Example 2
Project: solo-spring   File: Filler.java   View Source Code Vote up 7 votes
/**
 * Fills page navigations.
 *
 * @param dataModel
 *            data model
 * @throws ServiceException
 *             service exception
 */
private void fillPageNavigations(final Map<String, Object> dataModel) throws ServiceException {
	Stopwatchs.start("Fill Navigations");
	try {
		logger.debug("Filling page navigations....");
		final List<JSONObject> pages = pageDao.getPages();

		for (final JSONObject page : pages) {
			if ("page".equals(page.optString(Page.PAGE_TYPE))) {
				final String permalink = page.optString(Page.PAGE_PERMALINK);

				page.put(Page.PAGE_PERMALINK, Latkes.getServePath() + permalink);
			}
		}

		dataModel.put(Common.PAGE_NAVIGATIONS, pages);
	} catch (final RepositoryException e) {
		logger.error("Fills page navigations failed", e);
		throw new ServiceException(e);
	} finally {
		Stopwatchs.end();
	}
}
 
Example 3
Project: localcloud_fe   File: ForegroundService.java   View Source Code Vote up 6 votes
/**
 * Retrieves the resource ID of the app icon.
 *
 * @param settings A JSON dict containing the icon name.
 */
private int getIconResId(JSONObject settings) {
    Context context = getApplicationContext();
    Resources res   = context.getResources();
    String pkgName  = context.getPackageName();
    String icon     = settings.optString("icon", NOTIFICATION_ICON);

    // cordova-android 6 uses mipmaps
    int resId = getIconResId(res, icon, "mipmap", pkgName);

    if (resId == 0) {
        resId = getIconResId(res, icon, "drawable", pkgName);
    }

    return resId;
}
 
Example 4
Project: solo-spring   File: Sessions.java   View Source Code Vote up 6 votes
/**
 * Gets the current logged in user name with the specified request.
 *
 * @param request
 *            the specified request
 * @return the current user name or {@code null}
 */
public static String currentUserName(final HttpServletRequest request) {
	final HttpSession session = request.getSession(false);

	if (null != session) {
		final JSONObject user = (JSONObject) session.getAttribute(User.USER);

		return user.optString(User.USER_NAME);
	}

	return null;
}
 
Example 5
Project: Simpler   File: Attitude.java   View Source Code Vote up 6 votes
public static Attitude parse(JSONObject jsonObject) {
    if (null == jsonObject) {
        return null;
    }
    Attitude attitude = new Attitude();
    attitude.id = jsonObject.optLong("id", 0L);
    attitude.created_at = jsonObject.optString("created_at", "");
    attitude.attitude = jsonObject.optString("attitude", "");
    attitude.attitude_type = jsonObject.optInt("attitude_type", 0);
    attitude.last_attitude = jsonObject.optString("last_attitude", "");
    attitude.source_allowclick = jsonObject.optInt("source_allowclick", 0);
    attitude.source_type = jsonObject.optInt("source_type", 0);
    attitude.source = jsonObject.optString("source", "");
    attitude.user = User.parse(jsonObject.optJSONObject("user"));
    attitude.status = Status.parse(jsonObject.optJSONObject("status"));
    return attitude;
}
 
Example 6
Project: jiracli   File: ConversionUtils.java   View Source Code Vote up 6 votes
/**
 * Returns the parsed issue, never null
 */
public static Issue toIssue(WebService webService, JSONObject json) {
    String key = json.optString("key");
    if (key == null || key.isEmpty()) {
        throw new IllegalArgumentException("Invalid Json, missing key: " + json);
    }
    Issue issue = webService.getIssue(key, EMPTY_REQUEST);
    JSONObject fields = json.optJSONObject("fields");
    if (fields != null) {
        FieldMap fieldMap = issue.getFieldMap();
        for (String id : fields.keySet()) {
            Object val = fields.get(id);
            if (val == JSONObject.NULL) {
                val = null;
            }
            Field field = fieldMap.getFieldById(id);
            if (field == null) {
                field = new Field(issue, id, new Value(val));
                fieldMap.addField(field);
            } else if (!Objects.equals(val, field.getValue().get())) {
                field.getValue().set(val);
            }
        }
    }
    return issue;
}
 
Example 7
Project: Simpler   File: Card.java   View Source Code Vote up 6 votes
public static Card parse(JSONObject obj) {
    if (obj == null) {
        return null;
    }
    Card card = new Card();
    card.card_type = obj.optInt("card_type", 0);
    card.show_type = obj.optInt("show_type", 0);

    JSONArray cardGroups = obj.optJSONArray("card_group");
    if (cardGroups != null && cardGroups.length() > 0) {
        card.card_group = new ArrayList<>(cardGroups.length());
        for (int i = 0; i < cardGroups.length(); i++) {
            CardGroup cardGroup = CardGroup.parse(cardGroups.optJSONObject(i));
            if (cardGroup != null) {
                card.card_group.add(cardGroup);
            }
        }
    }
    card.openurl = obj.optString("openurl", "");

    card.mblog = MBlog.parse(obj.optJSONObject("mblog"));
    return card;
}
 
Example 8
Project: letv   File: c.java   View Source Code Vote up 5 votes
private static /* synthetic */ a a(c cVar, a aVar) {
    if (aVar != null && "toast".equals(aVar.k)) {
        JSONObject jSONObject = aVar.m;
        CharSequence optString = jSONObject.optString(WidgetRequestParam.REQ_PARAM_COMMENT_CONTENT);
        int optInt = jSONObject.optInt(DownloadVideoTable.COLUMN_DURATION);
        int i = 1;
        if (optInt < 2500) {
            i = 0;
        }
        Toast.makeText(cVar.b, optString, i).show();
        new Timer().schedule(new e(cVar, aVar), (long) i);
    }
    return a.NONE_ERROR;
}
 
Example 9
Project: Tangram-Android   File: BannerEntityCard.java   View Source Code Vote up 5 votes
@Override
public void parseWith(@NonNull JSONObject data, @NonNull MVHelper resolver) {
    this.mCells.clear();
    id = data.optString(Card.KEY_ID, id == null ? "" : id);
    this.cardType = data.optString(Card.KEY_TYPE);
    // parsing header
    if (Utils.isSupportHeaderFooter(cardType)) {
        JSONObject header = data.optJSONObject(Card.KEY_HEADER);
        parseHeaderCell(resolver, header);
    }

    // parsing body
    JSONArray componentArray = data.optJSONArray(Card.KEY_ITEMS);
    if (componentArray != null) {
        final int cellLength = componentArray.length();
        for (int i = 0; i < cellLength; i++) {
            final JSONObject cellData = componentArray.optJSONObject(i);
            BaseCell cell = createCell(resolver, cellData, true);
            try {
                if (cell != null) {
                    cell.extras.put(MVResolver.KEY_INDEX, cell.pos);
                }
            } catch (JSONException e) {
            }
        }
    }
    // parsing footer
    if (Utils.isSupportHeaderFooter(cardType)) {
        JSONObject footer = data.optJSONObject(Card.KEY_FOOTER);
        parseFooterCell(resolver, footer);
    }

    JSONObject styleJson = data.optJSONObject(Card.KEY_STYLE);

    parseStyle(styleJson);
}
 
Example 10
Project: IdealMedia   File: SkuDetails.java   View Source Code Vote up 5 votes
public SkuDetails(String itemType, String jsonSkuDetails) throws JSONException {
    mItemType = itemType;
    mJson = jsonSkuDetails;
    JSONObject o = new JSONObject(mJson);
    mSku = o.optString("productId");
    mType = o.optString("type");
    mPrice = o.optString("price");
    mTitle = o.optString("title");
    mDescription = o.optString("description");
}
 
Example 11
Project: cordova-plugin-firebase-sdk   File: Firebase.java   View Source Code Vote up 5 votes
private static String getConfigOption(final JSONObject config, final String key, final String defaultVal) {
    if (config.has(key)) {
        return config.optString(key);
    } else if (defaultVal != null && !defaultVal.equals("")) {
        return defaultVal;
    } else {
        return null;
    }
}
 
Example 12
Project: rapid-io-android   File: Message.java   View Source Code Vote up 5 votes
@Override
protected void parseJsonBody(@NonNull JSONObject jsonBody) {
	super.parseJsonBody(jsonBody);
	mCollectionId = jsonBody.optString(ATTR_COL_ID);
	mFetchId = jsonBody.optString(ATTR_FETCH_ID);
	mDocuments = jsonBody.optString(ATTR_DOCS);
}
 
Example 13
Project: SystemUITuner2   File: Purchase.java   View Source Code Vote up 5 votes
public Purchase(String itemType, String jsonPurchaseInfo, String signature) throws JSONException {
    mItemType = itemType;
    mOriginalJson = jsonPurchaseInfo;
    JSONObject o = new JSONObject(mOriginalJson);
    mOrderId = o.optString("orderId");
    mPackageName = o.optString("packageName");
    mSku = o.optString("productId");
    mPurchaseTime = o.optLong("purchaseTime");
    mPurchaseState = o.optInt("purchaseState");
    mDeveloperPayload = o.optString("developerPayload");
    mToken = o.optString("token", o.optString("purchaseToken"));
    mIsAutoRenewing = o.optBoolean("autoRenewing");
    mSignature = signature;
}
 
Example 14
Project: AndroidBackendlessChat   File: FileLruCache.java   View Source Code Vote up 4 votes
public InputStream get(String key, String contentTag) throws IOException {
    File file = new File(this.directory, Utility.md5hash(key));

    FileInputStream input = null;
    try {
        input = new FileInputStream(file);
    } catch (IOException e) {
        return null;
    }

    BufferedInputStream buffered = new BufferedInputStream(input, Utility.DEFAULT_STREAM_BUFFER_SIZE);
    boolean success = false;

    try {
        JSONObject header = StreamHeader.readHeader(buffered);
        if (header == null) {
            return null;
        }

        String foundKey = header.optString(HEADER_CACHEKEY_KEY);
        if ((foundKey == null) || !foundKey.equals(key)) {
            return null;
        }

        String headerContentTag = header.optString(HEADER_CACHE_CONTENT_TAG_KEY, null);

        if ((contentTag == null && headerContentTag != null) ||
                (contentTag != null && !contentTag.equals(headerContentTag))) {
            return null;
        }

        long accessTime = new Date().getTime();
        Logger.log(LoggingBehavior.CACHE, TAG, "Setting lastModified to " + Long.valueOf(accessTime) + " for "
                + file.getName());
        file.setLastModified(accessTime);

        success = true;
        return buffered;
    } finally {
        if (!success) {
            buffered.close();
        }
    }
}
 
Example 15
Project: boohee_v5.6   File: ax.java   View Source Code Vote up 4 votes
public void a(JSONObject jSONObject, Response response) {
    String optString = jSONObject.optString("photo_url");
    this.b.a(new ay(this, jSONObject.optString("photo_key"), optString));
}
 
Example 16
Project: amap   File: MainActivity.java   View Source Code Vote up 4 votes
@Override
public void onResponse(Call call, Response response) throws IOException {
    if (response.code() != 200) {
        // Toast.makeText(MainActivity.this, "服务器连接失败!", Toast.LENGTH_SHORT).show();
        return;
    }

    String result = response.body().string();
    LogUtil.d("result:" + result);
    try {
        JSONObject jsonObj = new JSONObject(result);
        if (jsonObj != null) {
            String retCode = jsonObj.optString("retCode");
            if (retCode != null && retCode.equals("0")) {
                // 在此处理业务逻辑
                JSONObject bizDataJsonObj = jsonObj.optJSONObject("bizData");
                if (bizDataJsonObj != null) {
                    String retVersionCode = bizDataJsonObj.optString("retVersionCode");
                    if ("0".equals(retVersionCode)) {
                        //不需要更新
                    } else if ("1".equals(retVersionCode)) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                SimpleDialog.forceShow(MainActivity.this, "检查到新版本,是否立刻升级?", null, new SimpleDialog.OnPositiveClickListener() {
                                    @Override
                                    public void onPositiveClick() {
                                        getAppDownloadUrl();
                                    }
                                });
                            }
                        });
                    }
                }
                return;
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
 
Example 17
Project: Blockly   File: FieldImage.java   View Source Code Vote up 4 votes
public static FieldImage fromJson(JSONObject json) {
    return new FieldImage(json.optString("name"),
            json.optString("src", "https://www.gstatic.com/codesite/ph/images/star_on.gif"),
            json.optInt("width", 15), json.optInt("height", 15),
            json.optString("alt", "*"));
}
 
Example 18
Project: siiMobilityAppKit   File: Calendar.java   View Source Code Vote up 4 votes
private static String getPossibleNullString(String param, JSONObject from) {
  return from.isNull(param) || "null".equals(from.optString(param)) ? null : from.optString(param);
}
 
Example 19
Project: boohee_v5.6   File: SportCourseActivity.java   View Source Code Vote up 4 votes
private void handleData(JSONObject object) {
    if (object != null) {
        this.mIntroduceURL = object.optString("link_url");
        this.mCourseID = object.optInt("sports_course_id");
        setTitle(object.optString("name"));
        JSONObject data = object.optJSONObject("sports_days");
        int total = data.optInt("total");
        int finished = data.optInt("finished");
        this.tv_course_count.setText(String.valueOf(total));
        this.tv_course_finished.setText(String.valueOf(finished));
        this.view_course_finish.setVisibility(total == finished ? 0 : 8);
        this.viewCourseProgress.setMax(total);
        this.viewCourseProgress.setProgress(finished);
        this.imageLoader.displayImage(data.optString("pic_url"), this.iv_header_bg,
                ImageLoaderOptions.randomColor());
        List<CourseInfo> courseInfos = FastJsonUtils.parseList(data.optString("sports_days"),
                CourseInfo.class);
        if (courseInfos != null && courseInfos.size() != 0) {
            this.mDataList.clear();
            this.mDataList.addAll(courseInfos);
            int todayID = data.optInt("today_id");
            int index = 1;
            List<FinishedCourseDay> finishedDayList = FastJsonUtils.parseList(data.optString
                    ("finish_days"), FinishedCourseDay.class);
            for (CourseInfo course : this.mDataList) {
                for (CourseItemInfo item : course.items) {
                    int index2 = index + 1;
                    item.index = index;
                    item.download = DownloadHelper.getInstance().hasDownload(item.video_url);
                    if (item.id == todayID) {
                        item.today = true;
                        if (this.mTabIndex == 0) {
                            this.mTabIndex = this.mDataList.indexOf(course);
                        }
                    } else {
                        item.today = false;
                    }
                    if (finishedDayList != null && finishedDayList.size() > 0) {
                        for (FinishedCourseDay day : finishedDayList) {
                            if (item.id == day.id) {
                                item.date = day.date;
                            }
                        }
                    }
                    index = index2;
                }
            }
            initView();
        }
    }
}
 
Example 20
Project: marathonv5   File: DisplayWindow.java   View Source Code Vote up 2 votes
/**
 * Get the default fixture from user preferrences.
 * 
 * @return
 */
public String getDefaultFixture() {
    JSONObject p = Preferences.instance().getSection("project");
    return p.optString("fixture", "default");
}