我遇到一些麻煩,我想會得到一個JSON格式數組對象的字符串,JSON對象不能GetString的
和陣列明確[{「代碼」:「123」,「路徑」 : 「456」},...}]
但
JArray.getJSONObject(0).getString("code")
工作時,它顯示 「空」
有沒有人可以解釋爲什麼會發生?
感謝您的解決方案
for(int i=0;i<JArray.length();i++) {
try {
avr_hash = JArray.getJSONObject(i).getString("code");
img_adress[JArray.length()] = JArray.getJSONObject(i).getString("path");
}catch (JSONException e){
Log.e("Catch obj",e.toString());
}
}
IDE:Android Studio中
解決方案:數組索引設置錯誤
不應該在循環中使用'i'而不是'exist_json_array_count'嗎? –
你是對的,但0或下一個 – JimmyHo