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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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

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

慕碼人8056858 2019-09-05 10:05:21
如何在嵌套的JSON結(jié)果中解析動態(tài)JSON密鑰?我有以下格式的JSON結(jié)果,JSON Lint將其顯示為“有效響應(yīng)”。我的問題是:如何訪問“question_mark”的內(nèi)容,因為“141”,“8911”等都是動態(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"             },我的問題標題“動態(tài)密鑰”可能是錯誤的,但我不知道在這一點上什么是這個問題的更好的名稱。任何幫助將不勝感激!
查看完整描述

3 回答

?
小怪獸愛吃肉

TA貢獻1852條經(jīng)驗 獲得超1個贊

使用JSONObject keys()獲取密鑰,然后迭代每個密鑰以獲取動態(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...
    }



查看完整回答
反對 回復(fù) 2019-09-09
  • 3 回答
  • 0 關(guān)注
  • 302 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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