本文整理了Java中org.json.JSONObject.optLong()
方法的一些代码示例,展示了JSONObject.optLong()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.optLong()
方法的具体详情如下:
包路径:org.json.JSONObject
类名称:JSONObject
方法名:optLong
[英]Returns the value mapped by name if it exists and is a long or can be coerced to a long. Returns 0 otherwise. Note that JSON represents numbers as doubles, so this is lossy; use strings to transfer numbers via JSON.
[中]返回按名称映射的值(如果该值存在且为long或可以强制为long)。否则返回0。请注意,JSON将数字表示为双精度,因此这是lossy;使用字符串通过JSON传输数字。
代码示例来源:origin: google/physical-web
/**
* Get extra long value.
* @param key The key of the stored value.
* @param defaultValue The value to return if the key does not exist or the value cannot be
* coerced into the necessary type.
* @return The stored value or the provided default if it doesn't exist in specified form.
*/
public long optExtraLong(String key, long defaultValue) {
return mExtraData.optLong(key, defaultValue);
}
代码示例来源:origin: google/physical-web
/**
* Get extra long value.
* @param key The key of the stored value.
* @return The stored value or 0 if it doesn't exist in specified form.
*/
public long optExtraLong(String key) {
return mExtraData.optLong(key);
}
代码示例来源:origin: google/physical-web
/**
* Get extra long value.
* @param key The key of the stored value.
* @return The stored value or 0 if it doesn't exist in specified form.
*/
public long optExtraLong(String key) {
return mExtraData.optLong(key);
}
代码示例来源:origin: google/physical-web
/**
* Get extra long value.
* @param key The key of the stored value.
* @param defaultValue The value to return if the key does not exist or the value cannot be
* coerced into the necessary type.
* @return The stored value or the provided default if it doesn't exist in specified form.
*/
public long optExtraLong(String key, long defaultValue) {
return mExtraData.optLong(key, defaultValue);
}
代码示例来源:origin: zzz40500/GsonFormat
/**
* Get an optional long value associated with a key, or zero if there is no
* such key or if the value is not a number. If the value is a string, an
* attempt will be made to evaluate it as a number.
*
* @param key
* A key string.
* @return An object which is the value.
*/
public long optLong(String key) {
return this.optLong(key, 0);
}
代码示例来源:origin: robovm/robovm
/**
* Returns the value mapped by {@code name} if it exists and is a long or
* can be coerced to a long. Returns 0 otherwise. Note that JSON represents numbers as doubles,
* so this is <a href="#lossy">lossy</a>; use strings to transfer numbers via JSON.
*/
public long optLong(String name) {
return optLong(name, 0L);
}
代码示例来源:origin: apache/geode
/**
* Returns the value mapped by {@code name} if it exists and is a long or can be coerced to a
* long, or 0 otherwise. Note that JSON represents numbers as doubles, so this is
* <a href="#lossy">lossy</a>; use strings to transfer numbers via JSON.
*
* @param name The name of the field we want.
* @return The selected value.
*/
public long optLong(String name) {
return optLong(name, 0L);
}
代码示例来源:origin: loklak/loklak_server
/**
* Get an optional long value associated with a key, or zero if there is no
* such key or if the value is not a number. If the value is a string, an
* attempt will be made to evaluate it as a number.
*
* @param key
* A key string.
* @return An object which is the value.
*/
public long optLong(String key) {
return this.optLong(key, 0);
}
代码示例来源:origin: apache/geode
public long getLong(String key) {
return jsonObject.optLong(key);
}
代码示例来源:origin: alibaba/Tangram-Android
public long optLongParam(String key) {
if (extras.has(key)) {
return extras.optLong(key);
}
if (style != null && style.extras != null) {
return style.extras.optLong(key);
}
return 0;
}
代码示例来源:origin: alibaba/Tangram-Android
public long optLongParam(String key) {
if (extras.has(key))
return extras.optLong(key);
if (style != null && style.extras != null)
return style.extras.optLong(key);
return 0;
}
代码示例来源:origin: facebook/facebook-android-sdk
@Override
public void onCompleted(GraphResponse response) {
JSONObject data = response.getJSONObject();
if (data == null) {
return;
}
refreshResult.accessToken = data.optString("access_token");
refreshResult.expiresAt = data.optInt("expires_at");
refreshResult.dataAccessExpirationTime =
data.optLong("data_access_expiration_time");
}
})
代码示例来源:origin: anjlab/android-inapp-billing-v3
public SkuDetails(JSONObject source) throws JSONException
{
String responseType = source.optString(Constants.RESPONSE_TYPE);
if (responseType == null)
{
responseType = Constants.PRODUCT_TYPE_MANAGED;
}
productId = source.optString(Constants.RESPONSE_PRODUCT_ID);
title = source.optString(Constants.RESPONSE_TITLE);
description = source.optString(Constants.RESPONSE_DESCRIPTION);
isSubscription = responseType.equalsIgnoreCase(Constants.PRODUCT_TYPE_SUBSCRIPTION);
currency = source.optString(Constants.RESPONSE_PRICE_CURRENCY);
priceLong = source.optLong(Constants.RESPONSE_PRICE_MICROS);
priceValue = priceLong / 1000000d;
priceText = source.optString(Constants.RESPONSE_PRICE);
subscriptionPeriod = source.optString(Constants.RESPONSE_SUBSCRIPTION_PERIOD);
subscriptionFreeTrialPeriod = source.optString(Constants.RESPONSE_FREE_TRIAL_PERIOD);
haveTrialPeriod = !TextUtils.isEmpty(subscriptionFreeTrialPeriod);
introductoryPriceLong = source.optLong(Constants.RESPONSE_INTRODUCTORY_PRICE_MICROS);
introductoryPriceValue = introductoryPriceLong / 1000000d;
introductoryPriceText = source.optString(Constants.RESPONSE_INTRODUCTORY_PRICE);
introductoryPricePeriod = source.optString(Constants.RESPONSE_INTRODUCTORY_PRICE_PERIOD);
haveIntroductoryPeriod = !TextUtils.isEmpty(introductoryPricePeriod);
introductoryPriceCycles = source.optInt(Constants.RESPONSE_INTRODUCTORY_PRICE_CYCLES);
}
代码示例来源:origin: czy1121/update
private static UpdateInfo parse(JSONObject o) {
UpdateInfo info = new UpdateInfo();
if (o == null) {
return info;
}
info.hasUpdate = o.optBoolean("hasUpdate", false);
if (!info.hasUpdate) {
return info;
}
info.isSilent = o.optBoolean("isSilent", false);
info.isForce = o.optBoolean("isForce", false);
info.isAutoInstall = o.optBoolean("isAutoInstall", !info.isSilent);
info.isIgnorable = o.optBoolean("isIgnorable", true);
info.versionCode = o.optInt("versionCode", 0);
info.versionName = o.optString("versionName");
info.updateContent = o.optString("updateContent");
info.url = o.optString("url");
info.md5 = o.optString("md5");
info.size = o.optLong("size", 0);
return info;
}
}
代码示例来源:origin: anjlab/android-inapp-billing-v3
PurchaseData parseResponseDataImpl()
{
try
{
JSONObject json = new JSONObject(responseData);
PurchaseData data = new PurchaseData();
data.orderId = json.optString(Constants.RESPONSE_ORDER_ID);
data.packageName = json.optString(Constants.RESPONSE_PACKAGE_NAME);
data.productId = json.optString(Constants.RESPONSE_PRODUCT_ID);
long purchaseTimeMillis = json.optLong(Constants.RESPONSE_PURCHASE_TIME, 0);
data.purchaseTime = purchaseTimeMillis != 0 ? new Date(purchaseTimeMillis) : null;
data.purchaseState = PurchaseState.values()[json.optInt(Constants.RESPONSE_PURCHASE_STATE, 1)];
data.developerPayload = json.optString(Constants.RESPONSE_DEVELOPER_PAYLOAD);
data.purchaseToken = json.getString(Constants.RESPONSE_PURCHASE_TOKEN);
data.autoRenewing = json.optBoolean(Constants.RESPONSE_AUTO_RENEWING);
return data;
}
catch (JSONException e)
{
Log.e(LOG_TAG, "Failed to parse response data", e);
return null;
}
}
代码示例来源:origin: ankidroid/Anki-Android
private long getModelIdFromUri(Uri uri, Collection col) {
String modelIdSegment = uri.getPathSegments().get(1);
long id;
if (modelIdSegment.equals(FlashCardsContract.Model.CURRENT_MODEL_ID)) {
id = col.getModels().current().optLong("id", -1);
} else {
try {
id = Long.parseLong(uri.getPathSegments().get(1));
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Model ID must be either numeric or the String CURRENT_MODEL_ID");
}
}
return id;
}
代码示例来源:origin: facebook/facebook-android-sdk
static AccessToken createFromJSONObject(JSONObject jsonObject) throws JSONException {
int version = jsonObject.getInt(VERSION_KEY);
if (version > CURRENT_JSON_FORMAT) {
throw new FacebookException("Unknown AccessToken serialization format.");
}
String token = jsonObject.getString(TOKEN_KEY);
Date expiresAt = new Date(jsonObject.getLong(EXPIRES_AT_KEY));
JSONArray permissionsArray = jsonObject.getJSONArray(PERMISSIONS_KEY);
JSONArray declinedPermissionsArray = jsonObject.getJSONArray(DECLINED_PERMISSIONS_KEY);
Date lastRefresh = new Date(jsonObject.getLong(LAST_REFRESH_KEY));
AccessTokenSource source = AccessTokenSource.valueOf(jsonObject.getString(SOURCE_KEY));
String applicationId = jsonObject.getString(APPLICATION_ID_KEY);
String userId = jsonObject.getString(USER_ID_KEY);
Date dataAccessExpirationTime = new Date(
jsonObject.optLong(DATA_ACCESS_EXPIRATION_TIME, 0));
return new AccessToken(
token,
applicationId,
userId,
Utility.jsonArrayToStringList(permissionsArray),
Utility.jsonArrayToStringList(declinedPermissionsArray),
source,
expiresAt,
lastRefresh,
dataAccessExpirationTime);
}
代码示例来源:origin: ankidroid/Anki-Android
/**
* Return the position of the deck in the deck list. If the deck is a child of a collapsed deck
* (i.e., not visible in the deck list), then the position of the parent deck is returned instead.
*
* An invalid deck ID will return position 0.
*/
public int findDeckPosition(long did) {
for (int i = 0; i < mDeckList.size(); i++) {
if (mDeckList.get(i).did == did) {
return i;
}
}
// If the deck is not in our list, we search again using the immediate parent
List<JSONObject> parents = mCol.getDecks().parents(did);
if (parents.size() == 0) {
return 0;
} else {
return findDeckPosition(parents.get(parents.size() - 1).optLong("id", 0));
}
}
代码示例来源:origin: ankidroid/Anki-Android
/**
* Get current model.
* @param forDeck If true, it tries to get the deck specified in deck by mid, otherwise or if the former is not
* found, it uses the configuration`s field curModel.
* @return The JSONObject of the model, or null if not found in the deck and in the configuration.
*/
public JSONObject current(boolean forDeck) {
JSONObject m = null;
if (forDeck) {
m = get(mCol.getDecks().current().optLong("mid", -1));
}
if (m == null) {
m = get(mCol.getConf().optLong("curModel", -1));
}
if (m == null) {
if (!mModels.isEmpty()) {
m = mModels.values().iterator().next();
}
}
return m;
}
代码示例来源:origin: ankidroid/Anki-Android
@Override
public void onPreExecute() {
mProgressDialog = StyledProgressDialog.show(DeckPicker.this, "",
getResources().getString(R.string.delete_deck), false);
if (did == getCol().getDecks().current().optLong("id")) {
removingCurrent = true;
}
}
内容来源于网络,如有侵权,请联系作者删除!