我有一個JSON鏈接,如果我們打開它,我得到以下結果安卓:動態獲取JSON數組的鍵名從JSON
{
"Status": "Success",
"All_Details": [{
"Types": "0",
"TotalPoints": "0",
"ExpiringToday": 0
}],
"First": [{
"id": "0",
"ImagePath": "http://first.example.png"
}],
"Second": [{
"id": "2",
"ImagePath": "http://second.example.png"
}],
"Third": [{
"id": "3",
"ImagePath": "http://third.example.png"
}],
}
我需要的是,我要動態獲取所有的關鍵名稱,如狀態,All_details,First等。
而且我還想獲取All_details和First Array中的數據。 我用下面的方法
@Override
public void onResponse(JSONObject response) throws JSONException {
VolleyLog.d(TAG, "Home Central OnResponse: " + response);
String statusStr = response.getString("Status");
Log.d(TAG, "Status: " + statusStr);
if (statusStr.equalsIgnoreCase("Success")) {
Iterator iterator = response.keys();
while (iterator.hasNext()) {
String key = (String)iterator.next();
}
}
}
我得到得到所有的鍵名存儲在字符串鍵。但我無法打開獲取JSON數組內的值,例如。我需要使用String(Key)來獲取第一個和第二個數組中的值。我怎樣才能做到這一點。???
非常感謝...其工作... – IndependentDev
@IndependentDev不客氣,很高興我可以幫助你:) –