The following JSON structure is available:

{ "response": { "count": 10, "items": [{ "id": 104755, "from_id": -1, "owner_id": -1, "date": 1483803000, "marked_as_ads": 0, "post_type": "postpone", "text": "Message", "can_edit": 1, "created_by": 1, "can_publish": 1, "can_delete": 1, "attachments": [{ "type": "video", "video": { "id": 1, "owner_id": -1, "title": "Title", "duration": 6, "description": "description", "date": 1483801275, "comments": 0, "views": 17, "photo_130": "https://pp.vk.me/...ideo/s_84ca8f4e.jpg", "photo_320": "https://pp.vk.me/...ideo/l_90217297.jpg", "photo_640": "https://pp.vk.me/...ideo/y_7c611865.jpg", "access_key": "43cbb785c00ac1bb0f", "platform": "Coub", "can_edit": 1, "can_add": 1 } }], "post_source": { "type": "api" }, "comments": { "count": 0, "can_post": 0 } }], "profiles": [], "groups": [{ "id": 80682837, "name": "Name", "screen_name": "Name", "is_closed": 0, "type": "page", "is_admin": 1, "admin_level": 3, "is_member": 1, "photo_50": "https://pp.vk.me/...4ea/bZj_J5bL_EM.jpg", "photo_100": "https://pp.vk.me/...4e9/55T6C3xKJkA.jpg", "photo_200": "https://pp.vk.me/...4e8/a_soitbpt3g.jpg" }, { "id": 1, "name": "Name", "screen_name": "club1", "is_closed": 0, "type": "group", "is_admin": 1, "admin_level": 3, "is_member": 1, "photo_50": "https://pp.vk.me/...500/k6TkTmhCSiA.jpg", "photo_100": "https://pp.vk.me/...4ff/Cb8hMKo9nSU.jpg", "photo_200": "https://pp.vk.me/...4fe/6jafptAHifc.jpg" }] } } 

I can't get to the value in "items": [{"attachments": [{"video": {"photo_640"}}]}] .
Please explain how to get to him?

 try { JSONObject jsonObject = (JSONObject) response.json.get("response"); JSONArray jsonArray = (JSONArray) jsonObject.get("items"); for (int i = 0; i < jsonArray.length(); i++) { JSONObject post = (JSONObject) jsonArray.get(i); // Posts mv = new Posts(post.getString("text").substring(post.getString("text").indexOf('\n') + 1), GetUTC(Long.parseLong(post.getString("date"))), post.getString("id"), "photo_640.jpg"); mvList.add(mv); } mAdapter.notifyDataSetChanged(); } catch (JSONException e) { e.printStackTrace(); } 
  • Show valid json. - post_zeew
  • The link probably should show the result of the request, but without authorization, it is not available. There are just docks on wall.get . - post_zeew
  • Edited a post. - Holofox

1 answer 1

If in order, then so:

 JSONObject response = jsonObject.getJSONObject("response"); JSONArray items = response.getJSONArray("items"); JSONObject item0 = items.getJSONObject(0); JSONArray attachments = item0.getJSONArray("attachments"); JSONObject attachment0 = attachments.getJSONObject(0); JSONObject video = attachment0.getJSONObject("video"); String videoLink = video.getString("photo_640");