使用下面的代码来解析json对象内的json数组。解析json数组时出现超出范围错误的索引
JSONObject notificationResponse = new JSONObject(response.toString());
JSONObject value = new JSONObject(notificationResponse.getString("value"));
JSONArray details = value.optJSONArray("details");
final int numberOfItems = details.length();
for (int i =0; i <= numberOfItems; i++){
JSONObject jsonObjects = details.getJSONObject(i);
String text = jsonObjects.getString("text");
String date = jsonObjects.getString("date & time");
Log.d(TAG,text + " " +date);
}
} catch (Exception e) {
e.printStackTrace();
}
以下是我的json。
{"status":1,"value":{"details":[{"text":"sample", "date & time":"12-NOV-15 3:30pm"}]}}
我的代码out of range
例外在JSONObject jsonObjects = details.getJSONObject(i);
只需更换for循环<=与<仅 – Manifest
除去等号条件 我