我有以下格式的JSON結果,其中JSON Lint顯示爲「有效響應」。如何解析嵌套JSON結果中的動態JSON密鑰?
我的問題是:如何訪問「question_mark」的內容,因爲「141」,「8911」等都是動態值?
我的示例代碼用於訪問「產品」的價值。
//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"
},
{
"product": "XYZ",
"id": "1129",
"question_mark": {
"379": {
"count": "379",
"more_desc": "this is xyz",
"seq": "5"
},
"845": {
"count": "845",
"more_desc": "this is table",
"seq": "6"
},
"12383": {
"count": "12383",
"more_desc": "Jumbo",
"seq": "4"
},
"257258": {
"count": "257258",
"more_desc": "large",
"seq": "1"
}
},
"name": "some other name",
"description": "this is some other product"
}
]
}
我的問題標題「動態密鑰」可能是錯的,但我不知道在這一點上有什麼針對此問題的更好的名字。
任何幫助將不勝感激!
我想你應該執行前具有內部question_mark對象的值。你有嗎? –
umm,no。我不知道如何訪問問號內的值。爲此,我必須做jsonObj.optJSONObject(「141」); 141是動態的,我不會提前知道它。 –