我試圖從JSONArray
內部數組中獲取值,我能夠成功檢索整個JSON值到JSONArray
但無法檢索JSONArray
中的值。當我將JSONArray
轉換爲JSONObject
以獲取存儲在JSONArray
中的值。它提供了錯誤:org.json.JSONException: No value for "banner"
Json數組內部檢索值Android
這裏是JSON代碼,我驗證JSON代碼jsonlint.com而事實證明,JSON是驗證,
[
\t {"code":"banner","moduletitle":0,
\t "banner":
\t \t [
\t \t \t {"image":"http://imageurl"},
\t \t \t {"image":"http://imageurl"},
\t \t \t {"image":"http://imageurl"}
\t \t ]
\t \t
\t }
]
餘米試圖在3小時也沒有運氣得到這個。我新的JSON,不知道JSON如何實際工作,也讀取鄰接GSON Library獲得JSON值。這裏是我的Java代碼。
JSONArray jsonObj = null;
String image_url = "";
String banner_code ="";
try {
jsonObj =new JSONArray(lib_function.getJSONUrl(jsontags.Top_Banner_JOSN_URLs));
Log.d("value retrun :","" +jsonObj);
//---vlaue is coming and print in Log ----//
} catch (JSONException e) {
Log.v("Error in Parser :", " " + e);
Log.d("no value retrun :", "failed to convert");
}
try{
JSONObject jo = new JSONObject();
JSONArray ja = new JSONArray();
// populate the array
jo.put("arrayName", jsonObj);
JSONArray subArray = jo.getJSONArray("banner");
image_url= subArray.getString(Integer.parseInt("image"));
Log.d("banner code",""+subArray);
}catch(Exception e)
{
Log.d("not working",""+e);
}
我folllow這個問題,但運氣: How to parse JSON Array inside another JSON Array in Android
如果有人建議,我在做錯誤的將是升值。或讓我知道,在哪裏我可以得到更多關於JSON的信息
UPDATE謝謝大家給他們寶貴的時間來回答我的愚蠢問題。所有答案都是正確的,但我只能接受一個答案。非常感謝所有
我的JSONArray創建另一個JSONObject的價值和通過指定鍵獲取值。 –