I am making a webservice call and the respond is in JSON. The content which i get, is a JSONArray and looks like this:
{"jsonrpc":"2.0","id":"req-002","result":[ {"id":125043,"date":20110117,"startTime":800,"endTime":850, "kl":[{"id":71}],"te":[{"id":23}],"su":[{"id":13}],"ro":[{"id":1}]}, {"id":125127,"date":20110117,"startTime":1055,"endTime":1145, "kl":[{"id":71}],"te":[{"id":41}],"su":[{"id":19}],"ro":[{"id":31}]}, ]}
Now i am trying to get the objects in the array, but i am only able to fetch the first array: for example i cant get the first "kl" array but i am not able to get the second one. It always give me the error :
org.json.JSONException: Index 1 out of range [0..1)
This is what i have tried:
JSONObject jsonResult = new JSONObject(s);
// Get the result object
JSONArray arr = jsonResult.getJSONArray("result");
Log.d("Arraylänge", String.valueOf(arr.length()));
for(int i=0; i<arr.length(); i++){
JSONObject c = arr.getJSONObject(i);
anfangStunde[i] = c.getString("startTime");
endeStunde[i] = c.getString("endTime");
JSONArray klArr = c.getJSONArray("kl");
for(int j=0; i<klArr.length(); j++)
{
JSONObject k = klArr.getJSONObject(j);
klassenID[j] = k.getString("id");
}