当前位置: 首页>>代码示例>>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;未经允许,请勿转载。