第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

請(qǐng)問如何在嵌套的JSON結(jié)果中解析動(dòng)態(tài)JSON密鑰

請(qǐng)問如何在嵌套的JSON結(jié)果中解析動(dòng)態(tài)JSON密鑰

縹緲止盈 2019-11-23 16:15:13
如何在嵌套的JSON結(jié)果中解析動(dòng)態(tài)JSON密鑰?我有以下格式的JSON結(jié)果,JSON Lint將其顯示為“有效響應(yīng)”。我的問題是:如何訪問“question_mark”的內(nèi)容,因?yàn)椤?41”,“8911”等都是動(dòng)態(tài)值?我的示例代碼用于訪問“product”的值。//Consider I have the first <code>JSONObject</code> of the "search_result" array and //I access it's "product" value as below.String product = jsonObject.optString("product"); //where jsonObject is of type JSONObject.//<code>product<code> now contains "abc".JSON:{  "status": "OK",  "search_result": [             {                 "product": "abc",                 "id": "1132",                 "question_mark": {                     "141": {                         "count": "141",                         "more_description": "this is abc",                         "seq": "2"                     },                     "8911": {                         "count": "8911",                         "more_desc": "this is cup",                         "seq": "1"                     }                 },                 "name": "some name",                 "description": "This is some product"             },我的問題標(biāo)題“動(dòng)態(tài)密鑰”可能是錯(cuò)誤的,但我不知道在這一點(diǎn)上什么是這個(gè)問題的更好的名稱。任何幫助將不勝感激!
查看完整描述

3 回答

?
白衣非少年

TA貢獻(xiàn)1155條經(jīng)驗(yàn) 獲得超0個(gè)贊

使用JSONObject keys()獲取密鑰,然后迭代每個(gè)密鑰以獲取動(dòng)態(tài)值。

代碼大致如下:

    // searchResult refers to the current element in the array "search_result"
    JSONObject questionMark = searchResult.getJSONObject("question_mark");
    Iterator keys = questionMark.keys();

    while(keys.hasNext()) {
        // loop to get the dynamic key
        String currentDynamicKey = (String)keys.next();

        // get the value of the dynamic key
        JSONObject currentDynamicValue = questionMark.getJSONObject(currentDynamicKey);

        // do something here with the value...
    }



查看完整回答
反對(duì) 回復(fù) 2019-11-24
  • 3 回答
  • 0 關(guān)注
  • 353 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)