मैं निम्न स्वरूप जो JSON Lint एक "वैध प्रतिक्रिया" के रूप में इस से पता चलता में एक JSON परिणाम है।नेस्टेड JSON परिणाम में गतिशील JSON कुंजी का विश्लेषण कैसे करें?
मेरा प्रश्न है: "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, नहीं। मुझे नहीं पता कि प्रश्न चिह्न के अंदर मूल्यों का उपयोग कैसे किया जाए। इसके लिए मुझे jsonObj.optJSONObject ("141") करना होगा; जहां 141 गतिशील है और मैं इसे पहले से नहीं जानता। –