I'm trying to parse a JSON response and pass the data to list view adapter.
This have worked:
private void parseJsonFeed(JSONObject response) {
try {
JSONArray feedArray = response.getJSONArray("feed");
for (int i = 0; i < feedArray.length(); i++) {
JSONObject feedObj = (JSONObject) feedArray.get(i);
..........
But this haven't:
private void parseJsonFeed(JSONObject response) {
try {
JSONArray feedArray = response.getJSONArray("feed");
for (int i = feedArray.length(); i > 1; i--) {
JSONObject feedObj = (JSONObject) feedArray.get(i);
..........
I need to parse the items from last to first, what I'm missing ? It's supposed to be an easy for statement but I've been trying for hours.
Use this instead:
for (int i = feedArray.length() - 1; i >= 0; i--) {
Remember that lists start from 0 and end at (length-1).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.