0

So I'd like to iterate over a JSON array with objects within it. Ive tried doing my research but all them tutorials out there explain how to do it with keyed JSON objects.

The JSON array looks like so:

 items:[{i know}, {what you did} ,{last summer}]
3
  • your json is not valid , first of all please validate it Commented Jun 30, 2015 at 10:21
  • thats just a snippet of what i would like to obtain Commented Jul 1, 2015 at 0:52
  • @bpA, its the actual object Commented Jul 1, 2015 at 0:52

1 Answer 1

3
 try {
        JSONObject jsonObject = new JSONObject(string);
        JSONArray jsonArray = jsonObject.getJSONArray("items");
        String array[] = new String[jsonArray.length()];
        for(int i=0;i<jsonArray.length();i++){
            array[i] = String.valueOf(jsonArray.getJSONObject(i));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.