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


Java JSONObject.optJSONObject方法代碼示例

本文整理匯總了Java中org.json.JSONObject.optJSONObject方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.optJSONObject方法的具體用法?Java JSONObject.optJSONObject怎麽用?Java JSONObject.optJSONObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.json.JSONObject的用法示例。


在下文中一共展示了JSONObject.optJSONObject方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: load

import org.json.JSONObject; //導入方法依賴的package包/類
private void load() {
	StatsManager.increment(DatabaseEnum.USER_LOADED);

	JSONObject guildObj = Database.opt(guild.getStringID());
	if(guildObj == null) {
		return;
	}

	JSONObject usersObj = guildObj.optJSONObject(DBGuild.USERS_KEY);
	if(usersObj == null) {
		return;
	}

	JSONObject userObj = usersObj.optJSONObject(Long.toString(userID));
	if(userObj == null) {
		return;
	}

	this.coins = userObj.optInt(COINS_KEY);
}
 
開發者ID:Shadorc,項目名稱:Shadbot,代碼行數:21,代碼來源:DBUser.java

示例2: isFrameOrIFrame

import org.json.JSONObject; //導入方法依賴的package包/類
private static boolean isFrameOrIFrame(JSONObject message) {
  String method = message.optString("method");
  JSONObject params = message.optJSONObject("params");

  if (NODE_INSERTED.equals(method)
      && params != null
      && "IFRAME".equals(params.optJSONObject("node").optString("nodeName"))) {
    return true;
  }
  if (NODE_INSERTED.equals(method)
      && params != null
      && "FRAME".equals(params.optJSONObject("node").optString("nodeName"))) {
    return true;
  }
  return false;
}
 
開發者ID:google,項目名稱:devtools-driver,代碼行數:17,代碼來源:EventFactory.java

示例3: decode

import org.json.JSONObject; //導入方法依賴的package包/類
@Override
void decode(JSONObject object) throws ProcBridgeException {
    try {
        String api = object.getString(Protocol.KEY_API);
        if (api.isEmpty()) {
            throw ProcBridgeException.malformedInputData();
        }
        this.api = api;

        JSONObject body = object.optJSONObject(Protocol.KEY_BODY);
        if (body != null) {
            this.body = body;
        }

    } catch (JSONException ex) {
        throw ProcBridgeException.malformedInputData();
    }
}
 
開發者ID:gongzhang,項目名稱:proc-bridge,代碼行數:19,代碼來源:Protocol.java

示例4: BehaviorOutput

import org.json.JSONObject; //導入方法依賴的package包/類
public BehaviorOutput(JSONObject json) {
    mGuid = json.optString(Keys.Guid);
    mBehavior = json.optString(Keys.Behavior);

    JSONObject params = json.optJSONObject(Keys.Parameters);
    if (params != null && params.length() > 0) {
        mParameters = ParameterValue.getParameterValueDict(params);
    }
}
 
開發者ID:pullstring,項目名稱:pullstring-android,代碼行數:10,代碼來源:BehaviorOutput.java

示例5: load

import org.json.JSONObject; //導入方法依賴的package包/類
private void load() {
	StatsManager.increment(DatabaseEnum.GUILD_LOADED);

	JSONObject guildObj = Database.opt(guild.getStringID());
	if(guildObj == null) {
		return;
	}

	JSONObject settingsObj = guildObj.optJSONObject(SETTINGS_KEY);
	if(settingsObj != null) {
		for(String settingKey : settingsObj.keySet()) {
			settingsMap.put(SettingEnum.valueOf(settingKey.toUpperCase()), settingsObj.get(settingKey));
		}
	}
}
 
開發者ID:Shadorc,項目名稱:Shadbot,代碼行數:16,代碼來源:DBGuild.java

示例6: NotifyOptions

import org.json.JSONObject; //導入方法依賴的package包/類
public NotifyOptions(String subscriberType, JSONObject json) throws JSONException {
  String idsStr = json.optString(Subscriber.IDS);
  subscriber = new Subscriber(subscriberType, StringUtil.getList(idsStr));
  frequency = json.getInt(FREQUENCY);
  method = json.getString(METHOD);
  smsNotify = json.optBoolean(SMS_NOTIFY);
  JSONObject repeatOptionsJson = json.optJSONObject(REPEAT_OPTIONS);
  if (repeatOptionsJson != null) {
    repeatOptions = new RepeatOptions(repeatOptionsJson);
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:12,代碼來源:EventSpec.java

示例7: Json2Entity

import org.json.JSONObject; //導入方法依賴的package包/類
public BaseBean Json2Entity(String content) {
    this.cashierInfo = new CashierInfo();
    EALogger.i(IDataSource.SCHEME_HTTP_TAG, "收銀台接口數據:" + content);
    try {
        JSONObject jo = new JSONObject(content);
        this.cashierInfo.setStatus(jo.optString("status"));
        this.cashierInfo.setMessage(jo.optString("message"));
        JSONObject result = jo.optJSONObject("result");
        if (result == null) {
            return this.cashierInfo;
        }
        JSONObject object = result.optJSONObject("payMentResult");
        if (object != null) {
            this.cashierInfo.setVersion(object.optString("version"));
            this.cashierInfo.setService(object.optString(NotificationCompat.CATEGORY_SERVICE));
            this.cashierInfo.setMerchant_business_id(object.optString("merchantBusinessId"));
            this.cashierInfo.setUser_id(object.optString(UserInfoDb.USER_ID));
            this.cashierInfo.setNotify_url(object.optString("notifyUrl"));
            this.cashierInfo.setMerchant_no(object.optString("merchantNo"));
            this.cashierInfo.setOut_trade_no(object.optString("outTradeNo"));
            this.cashierInfo.setPrice(object.optString("price"));
            this.cashierInfo.setCurrency(object.optString("currency"));
            this.cashierInfo.setPay_expire(object.optString("payExpire"));
            this.cashierInfo.setProduct_id(object.optString("productId"));
            this.cashierInfo.setProduct_name(object.optString("productName"));
            this.cashierInfo.setProduct_desc(object.optString("productDesc"));
            this.cashierInfo.setTimestamp(object.optString("timestamp"));
            this.cashierInfo.setKey_index(object.optString("keyIndex"));
            this.cashierInfo.setInput_charset(object.optString("inputCharset"));
            this.cashierInfo.setIp(object.optString("ip"));
            this.cashierInfo.setSign_type(object.optString("signType"));
            this.cashierInfo.setSign(object.optString(TradeInfo.SIGN));
            this.cashierInfo.setHb_fq(object.optString("hbFq"));
        }
        return this.cashierInfo;
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:40,代碼來源:ParserCashier.java

示例8: login

import org.json.JSONObject; //導入方法依賴的package包/類
@Override
public void login(String token, ShardInfo shardInfo, SessionReconnectQueue reconnectQueue) throws LoginException, RateLimitedException {
    setStatus(Status.LOGGING_IN);
    if(token == null || token.isEmpty()) throw new LoginException("Provided token was null or empty!");

    setToken(token);
    verifyToken();
    this.shardInfo = shardInfo;
    JDAImpl.LOG.info("Login Successful!");

    client = new ServerWebSocketClient(this, reconnectQueue, gatewayServer);

    JSONObject cachedPresence = gatewayServer.cachedPresence;
    if(cachedPresence != null) {
        JSONObject game = cachedPresence.optJSONObject("game");
        if(game != null) {
            getPresence().setPresence(
                    OnlineStatus.fromKey(cachedPresence.getString("status")),
                    Game.of(game.getString("name"), game.optString("url")),
                    cachedPresence.getBoolean("afk")
            );
        } else {
            getPresence().setPresence(
                    OnlineStatus.fromKey(cachedPresence.getString("status")),
                    null,
                    cachedPresence.getBoolean("afk")
            );
        }
        gatewayServer.cachedPresence = null;
    }

    if(shutdownHook != null) {
        Runtime.getRuntime().addShutdownHook(shutdownHook);
    }
}
 
開發者ID:natanbc,項目名稱:discord-bot-gateway,代碼行數:36,代碼來源:ServerJDA.java

示例9: isHotPointTokenInvalid

import org.json.JSONObject; //導入方法依賴的package包/類
private boolean isHotPointTokenInvalid(JSONObject object) {
    boolean isInvalid = false;
    JSONObject body = object.optJSONObject("body");
    if (!isNull(body) && TextUtils.equals(body.optString("code"), "403")) {
        isInvalid = true;
    }
    LogInfo.log("isHotPointTokenInvalid", "isInvalid : " + isInvalid);
    return isInvalid;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:10,代碼來源:LetvBaseParser.java

示例10: isPlayRecordTokenInvalid

import org.json.JSONObject; //導入方法依賴的package包/類
private boolean isPlayRecordTokenInvalid(JSONObject object) {
    boolean isInvalid = false;
    JSONObject header = object.optJSONObject("header");
    if (!isNull(header) && TextUtils.equals(header.optString("status"), "5")) {
        isInvalid = true;
    }
    LogInfo.log("playRecordTokenInvalid", "isInvalid : " + isInvalid);
    return isInvalid;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:10,代碼來源:LetvBaseParser.java

示例11: setCallback

import org.json.JSONObject; //導入方法依賴的package包/類
/**
 * Sets the callback which will be called when the request finishes.
 *
 * @param callback the callback
 */
public final void setCallback(final Callback callback) {
    // Wrap callback to parse debug response if Graph Debug Mode is Enabled.
    if (FacebookSdk.isLoggingBehaviorEnabled(LoggingBehavior.GRAPH_API_DEBUG_INFO)
            || FacebookSdk.isLoggingBehaviorEnabled(LoggingBehavior.GRAPH_API_DEBUG_WARNING)) {
        Callback wrapper = new Callback() {
            @Override
            public void onCompleted(GraphResponse response) {
                JSONObject responseObject = response.getJSONObject();
                JSONObject debug =
                        responseObject != null ? responseObject.optJSONObject(DEBUG_KEY) : null;
                JSONArray debugMessages =
                        debug != null ? debug.optJSONArray(DEBUG_MESSAGES_KEY) : null;
                if (debugMessages != null) {
                    for (int i = 0; i < debugMessages.length(); ++i) {
                        JSONObject debugMessageObject = debugMessages.optJSONObject(i);
                        String debugMessage = debugMessageObject != null
                                ? debugMessageObject.optString(DEBUG_MESSAGE_KEY)
                                : null;
                        String debugMessageType = debugMessageObject != null
                                ? debugMessageObject.optString(DEBUG_MESSAGE_TYPE_KEY)
                                : null;
                        String debugMessageLink = debugMessageObject != null
                                ? debugMessageObject.optString(DEBUG_MESSAGE_LINK_KEY)
                                : null;
                        if (debugMessage != null && debugMessageType != null) {
                            LoggingBehavior behavior = LoggingBehavior.GRAPH_API_DEBUG_INFO;
                            if (debugMessageType.equals("warning")) {
                                behavior = LoggingBehavior.GRAPH_API_DEBUG_WARNING;
                            }
                            if (!Utility.isNullOrEmpty(debugMessageLink)) {
                                debugMessage += " Link: " + debugMessageLink;
                            }
                            Logger.log(behavior, TAG, debugMessage);
                        }
                    }
                }
                if (callback != null) {
                    callback.onCompleted(response);
                }
            }
        };
        this.callback = wrapper;
    } else {
        this.callback = callback;
    }

}
 
開發者ID:eviltnan,項目名稱:kognitivo,代碼行數:53,代碼來源:GraphRequest.java

示例12: onResponse

import org.json.JSONObject; //導入方法依賴的package包/類
@Override
public void onResponse(Call call, Response response) throws IOException {
    if (response.code() != 200) {
        // Toast.makeText(SettingActivity.this, "服務器連接失敗!", Toast.LENGTH_SHORT).show();
        return;
    }
    String result = response.body().string();
    LogUtil.d("result:" + result);
    try {
        JSONObject jsonObj = new JSONObject(result);
        if (jsonObj != null) {
            String retCode = jsonObj.optString("retCode");
            if (retCode != null && retCode.equals("0")) {
                // 在此處理業務邏輯
                JSONObject bizDataJsonObj = jsonObj.optJSONObject("bizData");
                if (bizDataJsonObj != null) {
                    final String retVersionCode = bizDataJsonObj.optString("retVersionCode");
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            swipRefreshLayout.setRefreshing(false);

                            if ("0".equals(retVersionCode)) {
                                //不需要更新
                                SimpleDialog.show(SettingActivity.this, "已是最新版本,無需更新!");
                            } else if ("1".equals(retVersionCode)) {

                                SimpleDialog.forceShow(SettingActivity.this, "檢查到新版本,是否立刻升級?", null, new SimpleDialog.OnPositiveClickListener() {
                                    @Override
                                    public void onPositiveClick() {
                                        getAppDownloadUrl();
                                    }
                                });

                            }
                        }
                    });
                }
                return;
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
 
開發者ID:zhuyu1022,項目名稱:amap,代碼行數:46,代碼來源:SettingActivity.java

示例13: parseWith

import org.json.JSONObject; //導入方法依賴的package包/類
public void parseWith(@NonNull JSONObject data, @NonNull final MVHelper resolver, boolean isParseCell) {
    if (TangramBuilder.isPrintLog()) {
        if (serviceManager == null) {
            throw new RuntimeException("serviceManager is null when parsing card");
        }
    }

    this.extras = data;
    this.type = data.optInt(KEY_TYPE, type);
    this.stringType = data.optString(KEY_TYPE);
    id = data.optString(KEY_ID, id == null ? "" : id);

    loadMore = data.optInt(KEY_LOAD_TYPE, 0) == LOAD_TYPE_LOADMORE;
    //you should alway assign hasMore to indicate there's more data explicitly
    if (data.has(KEY_HAS_MORE)) {
        hasMore = data.optBoolean(KEY_HAS_MORE);
    } else {
        if (data.has(KEY_LOAD_TYPE)) {
            hasMore = data.optInt(KEY_LOAD_TYPE) == LOAD_TYPE_LOADMORE;
        }
    }
    load = data.optString(KEY_API_LOAD, null);
    loadParams = data.optJSONObject(KEY_API_LOAD_PARAMS);
    loaded = data.optBoolean(KEY_LOADED, false);

    maxChildren = data.optInt(KEY_MAX_CHILDREN, maxChildren);
    // parsing header
    if (Utils.isSupportHeaderFooter(stringType) && isParseCell) {
        JSONObject header = data.optJSONObject(KEY_HEADER);
        parseHeaderCell(resolver, header);
    }

    // parsing body
    JSONArray componentArray = data.optJSONArray(KEY_ITEMS);
    if (componentArray != null && isParseCell) {
        final int cellLength = Math.min(componentArray.length(), maxChildren);
        for (int i = 0; i < cellLength; i++) {
            final JSONObject cellData = componentArray.optJSONObject(i);
            createCell(resolver, cellData, true);
        }
    }
    // parsing footer
    if (Utils.isSupportHeaderFooter(stringType) && isParseCell) {
        JSONObject footer = data.optJSONObject(KEY_FOOTER);
        parseFooterCell(resolver, footer);
    }

    JSONObject styleJson = data.optJSONObject(KEY_STYLE);

    parseStyle(styleJson);

}
 
開發者ID:alibaba,項目名稱:Tangram-Android,代碼行數:53,代碼來源:Card.java

示例14: handleData

import org.json.JSONObject; //導入方法依賴的package包/類
private void handleData(JSONObject object) {
    if (object != null) {
        this.mIntroduceURL = object.optString("link_url");
        this.mCourseID = object.optInt("sports_course_id");
        setTitle(object.optString("name"));
        JSONObject data = object.optJSONObject("sports_days");
        int total = data.optInt("total");
        int finished = data.optInt("finished");
        this.tv_course_count.setText(String.valueOf(total));
        this.tv_course_finished.setText(String.valueOf(finished));
        this.view_course_finish.setVisibility(total == finished ? 0 : 8);
        this.viewCourseProgress.setMax(total);
        this.viewCourseProgress.setProgress(finished);
        this.imageLoader.displayImage(data.optString("pic_url"), this.iv_header_bg,
                ImageLoaderOptions.randomColor());
        List<CourseInfo> courseInfos = FastJsonUtils.parseList(data.optString("sports_days"),
                CourseInfo.class);
        if (courseInfos != null && courseInfos.size() != 0) {
            this.mDataList.clear();
            this.mDataList.addAll(courseInfos);
            int todayID = data.optInt("today_id");
            int index = 1;
            List<FinishedCourseDay> finishedDayList = FastJsonUtils.parseList(data.optString
                    ("finish_days"), FinishedCourseDay.class);
            for (CourseInfo course : this.mDataList) {
                for (CourseItemInfo item : course.items) {
                    int index2 = index + 1;
                    item.index = index;
                    item.download = DownloadHelper.getInstance().hasDownload(item.video_url);
                    if (item.id == todayID) {
                        item.today = true;
                        if (this.mTabIndex == 0) {
                            this.mTabIndex = this.mDataList.indexOf(course);
                        }
                    } else {
                        item.today = false;
                    }
                    if (finishedDayList != null && finishedDayList.size() > 0) {
                        for (FinishedCourseDay day : finishedDayList) {
                            if (item.id == day.id) {
                                item.date = day.date;
                            }
                        }
                    }
                    index = index2;
                }
            }
            initView();
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:52,代碼來源:SportCourseActivity.java

示例15: onCreate

import org.json.JSONObject; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Entity$$CREATOR.create("", false);
    limitJsonTv = (TextView) findViewById(R.id.limitjson_ms);
    try {
        JSONObject root = new JSONObject("");
        root.opt("");
        root.optInt("");
        root.optBoolean("");
        root.optLong("");
        float aa = (float) root.optDouble("");
        root.optString("");

        root.optJSONObject("");
        root.optJSONArray("");
        int[] a;
        if (root.has("arr")) {
            JSONArray array = root.optJSONArray("");
            int size = array.length();
            a = new int[size];
            for (int i = 0; i < size; i++) {
                a[i] = array.optInt(i);
            }
        }


    } catch (JSONException e) {
        e.printStackTrace();
    }

    testLimitJson();

    LinearGraphView tu = (LinearGraphView) findViewById(R.id.line_graphic);

    ArrayList<Double> yList = new ArrayList<Double>();
    yList.add((double) 2.103);
    yList.add(4.05);
    yList.add(6.60);
    yList.add(3.08);
    yList.add(4.32);
    yList.add(2.0);
    yList.add(1115.0);

    ArrayList<String> xRawDatas = new ArrayList<String>();
    xRawDatas.add("05-19");
    xRawDatas.add("05-20");
    xRawDatas.add("05-21");
    xRawDatas.add("05-22");
    xRawDatas.add("05-23");
    xRawDatas.add("05-24");
    xRawDatas.add("05-25");
    xRawDatas.add("05-26");
    tu.setData(yList, xRawDatas, 8, 2);
}
 
開發者ID:freelifer,項目名稱:limitjson,代碼行數:57,代碼來源:MainActivity.java


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