我有這樣的代碼,的jArrAnswer
值是機器人JSONException索引1超出範圍[0..1](解析1個內循環2個JSON陣列)
[{"answer":"Yes"},{"answer":"No"},{"answer":"maybe"},{"answer":"yrg"}]
從jArrAnswer.length()
結果4
但爲什麼我得到錯誤
org.json.JSONException:指數1超出範圍[0..1)。
try {
JSONArray jArrAnswerid = new JSONArray(answerid);
JSONArray jArrAnswer = new JSONArray(answer);
for (int i = 0; i < jArrAnswer.length(); i++) {
JSONObject jObjAnswerid = jArrAnswerid.getJSONObject(i);
JSONObject jObjAnswer = jArrAnswer.getJSONObject(i);
String ansid = jObjAnswerid.getString("answerid");
String ans= jObjAnswer.getString("answer");
GroupModel item2 = new GroupModel(String.valueOf(i + 1), ans, ansid);
}
} catch (Exception e) {
Log.w("asdf", e.toString());
}
能否請您發表您的JSON響應? –
什麼是'jArrAnswerid.length()'? –
檢查我的編輯職位 – Lukmanpryg