當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONObject.optBoolean方法代碼示例

本文整理匯總了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();
}
 
開發者ID:SUTFutureCoder,項目名稱:localcloud_fe,代碼行數:21,代碼來源:ForegroundService.java

示例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;
}
 
開發者ID:growingio,項目名稱:react-native-growingio,代碼行數:24,代碼來源:GrowingIOModule.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:25,代碼來源:UpdateInfo.java

示例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;
}
 
開發者ID:privacyidea,項目名稱:privacyidea-authenticator,代碼行數:20,代碼來源:Util.java

示例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();
}
 
開發者ID:SUTFutureCoder,項目名稱:localcloud_fe,代碼行數:44,代碼來源:ForegroundService.java

示例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");
}
 
開發者ID:natanbc,項目名稱:discord-bot-gateway,代碼行數:24,代碼來源:CachedChannel.java

示例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) {
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:14,代碼來源:StoryDetailActivity.java

示例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");
}
 
開發者ID:natanbc,項目名稱:discord-bot-gateway,代碼行數:8,代碼來源:CachedUser.java

示例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);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:13,代碼來源:DefaultSettingsJsonTransform.java

示例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;
}
 
開發者ID:HitRoxxx,項目名稱:FloatingNew,代碼行數:15,代碼來源:Purchase.java

示例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();
    }
}
 
開發者ID:brevent,項目名稱:prevent,代碼行數:13,代碼來源:PreventUtils.java

示例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));
}
 
開發者ID:Axe-Ishmael,項目名稱:Blockly,代碼行數:9,代碼來源:FieldCheckbox.java

示例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;
}
 
開發者ID:alibaba,項目名稱:atlas,代碼行數:73,代碼來源:BundleListingUtil.java

示例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;
}
 
開發者ID:eviltnan,項目名稱:kognitivo,代碼行數:48,代碼來源:LikeActionController.java

示例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;
}
 
開發者ID:waylife,項目名稱:ViewDebugHelper,代碼行數:47,代碼來源:CheckUpdateTask.java


注:本文中的org.json.JSONObject.optBoolean方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。