本文整理汇总了Java中org.json.JSONObject.optString方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.optString方法的具体用法?Java JSONObject.optString怎么用?Java JSONObject.optString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.optString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import org.json.JSONObject; //导入方法依赖的package包/类
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;
}
示例2: fillPageNavigations
import org.json.JSONObject; //导入方法依赖的package包/类
/**
* 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();
}
}
示例3: getIconResId
import org.json.JSONObject; //导入方法依赖的package包/类
/**
* 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;
}
示例4: currentUserName
import org.json.JSONObject; //导入方法依赖的package包/类
/**
* 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;
}
示例5: parse
import org.json.JSONObject; //导入方法依赖的package包/类
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;
}
示例6: toIssue
import org.json.JSONObject; //导入方法依赖的package包/类
/**
* 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;
}
示例7: parse
import org.json.JSONObject; //导入方法依赖的package包/类
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;
}
示例8: a
import org.json.JSONObject; //导入方法依赖的package包/类
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;
}
示例9: parseWith
import org.json.JSONObject; //导入方法依赖的package包/类
@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);
}
示例10: SkuDetails
import org.json.JSONObject; //导入方法依赖的package包/类
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");
}
示例11: getConfigOption
import org.json.JSONObject; //导入方法依赖的package包/类
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;
}
}
示例12: parseJsonBody
import org.json.JSONObject; //导入方法依赖的package包/类
@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);
}
示例13: Purchase
import org.json.JSONObject; //导入方法依赖的package包/类
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;
}
示例14: get
import org.json.JSONObject; //导入方法依赖的package包/类
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();
}
}
}
示例15: a
import org.json.JSONObject; //导入方法依赖的package包/类
public void a(JSONObject jSONObject, Response response) {
String optString = jSONObject.optString("photo_url");
this.b.a(new ay(this, jSONObject.optString("photo_key"), optString));
}