本文整理匯總了Java中org.json.JSONObject.optBoolean方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.optBoolean方法的具體用法?Java JSONObject.optBoolean怎麽用?Java JSONObject.optBoolean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.optBoolean方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: keepAwake
import org.json.JSONObject; //導入方法依賴的package包/類
/**
* Put the service in a foreground state to prevent app from being killed
* by the OS.
*/
private void keepAwake() {
JSONObject settings = BackgroundMode.getSettings();
boolean isSilent = settings.optBoolean("silent", false);
if (!isSilent) {
startForeground(NOTIFICATION_ID, makeNotification());
}
PowerManager powerMgr = (PowerManager)
getSystemService(POWER_SERVICE);
wakeLock = powerMgr.newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK, "BackgroundMode");
wakeLock.acquire();
}
示例2: getConfigFromOptions
import org.json.JSONObject; //導入方法依賴的package包/類
private Configuration getConfigFromOptions(JSONObject options) {
Configuration config = new Configuration();
if (options.has("growingio_url_scheme")) {
config.setURLScheme(options.optString("growingio_url_scheme", "default_url_scheme"));
} else {
config.setURLScheme("default_url_scheme");
}
if (options.has("channel")) {
config.setChannel(options.optString("channel", ""));
}
if (options.has("useid")) {
if (options.optBoolean("useid", true))
config.useID();
}
if (options.has("debug")) {
config.setDebugMode(options.optBoolean("debug", false));
}
return config;
}
示例3: parse
import org.json.JSONObject; //導入方法依賴的package包/類
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;
}
示例4: makeTokenFromJSON
import org.json.JSONObject; //導入方法依賴的package包/類
private static Token makeTokenFromJSON(JSONObject o) throws JSONException {
Token tmp = new Token(new Base32().decode(o.getString(SECRET)), o.getString(LABEL), o.getString(TYPE), o.getInt(DIGITS));
tmp.setAlgorithm(o.getString(ALGORITHM));
if (o.getString(TYPE).equals(HOTP)) {
tmp.setCounter(o.getInt(COUNTER));
}
if (o.getString(TYPE).equals(TOTP)) {
tmp.setPeriod(o.getInt(PERIOD));
}
if (o.optBoolean(WITHPIN, false)) {
tmp.setWithPIN(true);
tmp.setPin(o.getString(PIN));
tmp.setLocked(true);
}
if (o.optBoolean(TAPTOSHOW, false)) {
tmp.setWithTapToShow(true);
}
return tmp;
}
示例5: makeNotification
import org.json.JSONObject; //導入方法依賴的package包/類
/**
* Create a notification as the visible part to be able to put the service
* in a foreground state.
*
* @param settings The config settings
*/
private Notification makeNotification(JSONObject settings) {
String title = settings.optString("title", NOTIFICATION_TITLE);
String text = settings.optString("text", NOTIFICATION_TEXT);
boolean bigText = settings.optBoolean("bigText", false);
Context context = getApplicationContext();
String pkgName = context.getPackageName();
Intent intent = context.getPackageManager()
.getLaunchIntentForPackage(pkgName);
Notification.Builder notification = new Notification.Builder(context)
.setContentTitle(title)
.setContentText(text)
.setOngoing(true)
.setSmallIcon(getIconResId(settings));
if (settings.optBoolean("hidden", true)) {
notification.setPriority(Notification.PRIORITY_MIN);
}
if (bigText || text.contains("\n")) {
notification.setStyle(
new Notification.BigTextStyle().bigText(text));
}
setColor(notification, settings);
if (intent != null && settings.optBoolean("resume")) {
PendingIntent contentIntent = PendingIntent.getActivity(
context, NOTIFICATION_ID, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
notification.setContentIntent(contentIntent);
}
return notification.build();
}
示例6: update
import org.json.JSONObject; //導入方法依賴的package包/類
@Override
public void update(JSONObject json) {
position = json.optInt("position");
if(overwrites == null) overwrites = new TLongObjectHashMap<>();
TLongSet toRemove = new TLongHashSet(overwrites.keys());
JSONArray array = json.getJSONArray("permission_overwrites");
for(int i = 0, j = array.length(); i < j; i++) {
JSONObject overwrite = array.getJSONObject(i);
long id = overwrite.getLong("id");
toRemove.remove(id);
overwrites.put(id, new CachedOverwrite(overwrite));
}
for(TLongIterator it = toRemove.iterator(); it.hasNext();) {
overwrites.remove(it.next());
}
name = json.optString("name");
topic = json.optString("topic");
nsfw = json.optBoolean("nsfw");
lastMessageId = json.optLong("last_message_id");
bitrate = json.optInt("bitrate");
userLimit = json.optInt("user_limit");
parentId = json.optLong("parent_id");
}
示例7: refreshCollect
import org.json.JSONObject; //導入方法依賴的package包/類
private void refreshCollect(JSONObject object) {
try {
this.isFavorite = object.optBoolean("exist");
this.favoriteId = object.optInt("id");
if (this.isFavorite) {
this.cbCollect.setChecked(true);
this.cbCollect.setText("已收藏");
return;
}
this.cbCollect.setText("收藏");
} catch (Exception e) {
}
}
示例8: update
import org.json.JSONObject; //導入方法依賴的package包/類
@Override
public void update(JSONObject json) {
if(!json.isNull("username")) username = json.getString("username");
if(!json.isNull("discriminator")) discriminator = (short)json.getInt("discriminator");
if(!json.isNull("avatar")) avatar = json.getString("avatar");
bot = json.optBoolean("bot");
}
示例9: buildAppDataFrom
import org.json.JSONObject; //導入方法依賴的package包/類
private AppSettingsData buildAppDataFrom(JSONObject json) throws JSONException {
String identifier = json.getString(SettingsJsonConstants.APP_IDENTIFIER_KEY);
String status = json.getString("status");
String url = json.getString("url");
String reportsUrl = json.getString(SettingsJsonConstants.APP_REPORTS_URL_KEY);
boolean updateRequired = json.optBoolean(SettingsJsonConstants.APP_UPDATE_REQUIRED_KEY, false);
AppIconSettingsData icon = null;
if (json.has(SettingsJsonConstants.APP_ICON_KEY) && json.getJSONObject(SettingsJsonConstants.APP_ICON_KEY).has(SettingsJsonConstants.ICON_HASH_KEY)) {
icon = buildIconDataFrom(json.getJSONObject(SettingsJsonConstants.APP_ICON_KEY));
}
return new AppSettingsData(identifier, status, url, reportsUrl, updateRequired, icon);
}
示例10: 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;
}
示例11: updateBooleanPreference
import org.json.JSONObject; //導入方法依賴的package包/類
private static void updateBooleanPreference(SharedPreferences sp, JSONObject json, String key) {
boolean defaultValue = json.optBoolean(key);
boolean value = !defaultValue;
try {
value = sp.getBoolean(key, value);
} catch (ClassCastException e) {
UILog.d(INVALID_VALUE + key, e);
}
if (value != defaultValue) {
sp.edit().putBoolean(key, defaultValue).apply();
}
}
示例12: fromJson
import org.json.JSONObject; //導入方法依賴的package包/類
public static FieldCheckbox fromJson(JSONObject json) throws BlockLoadingException {
String name = json.optString("name");
if (TextUtils.isEmpty(name)) {
throw new BlockLoadingException("field_checkbox \"name\" attribute must not be empty.");
}
return new FieldCheckbox(name, json.optBoolean("checked", true));
}
示例13: parseArray
import org.json.JSONObject; //導入方法依賴的package包/類
public static LinkedHashMap<String,BundleListing.BundleInfo> parseArray(String listingStr) throws Exception{
LinkedHashMap<String,BundleListing.BundleInfo> infos= new LinkedHashMap<>();
JSONArray array = new JSONArray(listingStr);
for(int x=0; x<array.length(); x++){
JSONObject object = array.getJSONObject(x);
BundleListing.BundleInfo info = new BundleListing.BundleInfo();
info.name = object.optString("name");
info.pkgName = object.optString("pkgName");
info.applicationName = object.optString("applicationName");
info.version = object.optString("version");
info.desc = object.optString("desc");
info.url = object.optString("url");
info.md5 = object.optString("md5");
String uniqueTag = object.optString("unique_tag");
if(TextUtils.isEmpty(uniqueTag)){
throw new IOException("uniqueTag is empty");
}
info.unique_tag = object.optString("unique_tag");
if (object.has("isInternal")) {
info.isInternal = object.optBoolean("isInternal");
}
JSONArray dependency = object.optJSONArray("dependency");
if(dependency!=null && dependency.length()>0){
List<String> dependencyList = new ArrayList<String>();
for(int i=0; i<dependency.length(); i++){
dependencyList.add(dependency.getString(i));
}
info.setDependency(dependencyList);
}
JSONArray activities = object.optJSONArray("activities");
if(activities!=null && activities.length()>0){
HashMap<String,Boolean> activitiesList = new HashMap<String,Boolean>();
for(int i=0; i<activities.length(); i++){
activitiesList.put(activities.getString(i),Boolean.FALSE);
}
info.activities = activitiesList;
}
JSONArray services = object.optJSONArray("services");
if(services!=null && services.length()>0){
HashMap<String,Boolean> servicesList = new HashMap<String,Boolean>();
for(int i=0; i<services.length(); i++){
servicesList.put(services.getString(i),Boolean.FALSE);
}
info.services = servicesList;
}
JSONArray receivers = object.optJSONArray("receivers");
if(receivers!=null && receivers.length()>0){
HashMap<String,Boolean> receiversList = new HashMap<String,Boolean>();
for(int i=0; i<receivers.length(); i++){
receiversList.put(receivers.getString(i),Boolean.FALSE);
}
info.receivers = receiversList;
}
JSONArray contentProviders = object.optJSONArray("contentProviders");
if(contentProviders!=null && contentProviders.length()>0){
HashMap<String,Boolean> contentProvidersList = new HashMap<String,Boolean>();
for(int i=0; i<contentProviders.length(); i++){
contentProvidersList.put(contentProviders.getString(i),Boolean.FALSE);
}
info.contentProviders = contentProvidersList;
}
infos.put(info.getPkgName(),info);
}
return infos.size()>0 ? infos : null;
}
示例14: deserializeFromJson
import org.json.JSONObject; //導入方法依賴的package包/類
private static LikeActionController deserializeFromJson(String controllerJsonString) {
LikeActionController controller;
try {
JSONObject controllerJson = new JSONObject(controllerJsonString);
int version = controllerJson.optInt(JSON_INT_VERSION_KEY, -1);
if (version != LIKE_ACTION_CONTROLLER_VERSION) {
// Don't attempt to deserialize a controller that might be serialized differently
// than expected.
return null;
}
String objectId = controllerJson.getString(JSON_STRING_OBJECT_ID_KEY);
int objectTypeInt = controllerJson.optInt(
JSON_INT_OBJECT_TYPE_KEY,
LikeView.ObjectType.UNKNOWN.getValue());
controller = new LikeActionController(
objectId,
LikeView.ObjectType.fromInt(objectTypeInt));
// Make sure to default to null and not empty string, to keep the logic elsewhere
// functioning properly.
controller.likeCountStringWithLike =
controllerJson.optString(JSON_STRING_LIKE_COUNT_WITH_LIKE_KEY, null);
controller.likeCountStringWithoutLike =
controllerJson.optString(JSON_STRING_LIKE_COUNT_WITHOUT_LIKE_KEY, null);
controller.socialSentenceWithLike =
controllerJson.optString(JSON_STRING_SOCIAL_SENTENCE_WITH_LIKE_KEY, null);
controller.socialSentenceWithoutLike =
controllerJson.optString(JSON_STRING_SOCIAL_SENTENCE_WITHOUT_LIKE_KEY, null);
controller.isObjectLiked = controllerJson.optBoolean(JSON_BOOL_IS_OBJECT_LIKED_KEY);
controller.unlikeToken = controllerJson.optString(JSON_STRING_UNLIKE_TOKEN_KEY, null);
JSONObject analyticsJSON = controllerJson.optJSONObject(
JSON_BUNDLE_FACEBOOK_DIALOG_ANALYTICS_BUNDLE);
if (analyticsJSON != null) {
controller.facebookDialogAnalyticsBundle =
BundleJSONConverter.convertToBundle(analyticsJSON);
}
} catch (JSONException e) {
Log.e(TAG, "Unable to deserialize controller from JSON", e);
controller = null;
}
return controller;
}
示例15: parseResult
import org.json.JSONObject; //導入方法依賴的package包/類
private CheckUpdateUtil.CheckUpdateItem parseResult(Context context, String result) {
CheckUpdateUtil.CheckUpdateItem item = new CheckUpdateUtil.CheckUpdateItem();
if (!TextUtils.isEmpty(result)) {
try {
JSONObject releaseJson = new JSONObject(result);
//version code and version name are hiding in tag_name, as tag_name format is always like "xxxx#VersionCode#VersionName"
String latestTag = releaseJson.optString("tag_name");
int serverVersionCode = 0;
String serverVersionName = "";
boolean isPreRelease = releaseJson.optBoolean("prerelease");
String body = releaseJson.optString("body");
JSONArray assetsJsonArray = releaseJson.optJSONArray("assets");
String downloadUrl = "";
if (assetsJsonArray != null && assetsJsonArray.length() > 0) {
JSONObject assetJsonObject = assetsJsonArray.getJSONObject(0);
if (assetJsonObject != null) {
downloadUrl = assetJsonObject.optString("browser_download_url");
//"VDH-${defaultConfig.versionName}-${defaultConfig.versionCode}" + time + ".apk"
String name = assetJsonObject.optString("name");
if (!TextUtils.isEmpty(name)) {
String arr[] = name.split("-");
if (arr.length >= 3) {
serverVersionName = arr[1];
serverVersionCode = SafeUtil.toInt(arr[2], 0);
}
}
}
}
item.isAlphaVersion = isPreRelease;
item.currentVersionCode = AppUtil.getVersionCode(context);
item.currentVersionName = AppUtil.getVersionName(context);
item.updateBody = body;
item.serverVersionCode = serverVersionCode;
item.serverVersionName = serverVersionName;
item.downloadUrl = downloadUrl;
item.resultCode = CheckUpdateUtil.CheckUpdateItem.RESULT_SUCCESS;
} catch (JSONException e) {
item.resultCode = CheckUpdateUtil.CheckUpdateItem.RESULT_FAIL;
}
} else {
item.resultCode = CheckUpdateUtil.CheckUpdateItem.RESULT_FAIL;
}
XLog.i("CheckUpdate", "item=" + (item != null ? item.toString() : "null"));
return item;
}