如何从webservice响应后反转json数组?

Pal*_*rma 1 java android blackberry

我得到了回应

{
    "success": 1,
    "message": "some message",
    "data": [
        {
            "comment_id": "43906",
            "comp_id": "116725",
            "user_id": "48322",
            "agree": "0",
            .....
            "replies": [....]
        },
        {
            "comment_id": "43905",
            "comp_id": "116725",
            "user_id": "48248",
            "agree": "0",
            .......
            "replies": [...]
        }
    ] 
}
Run Code Online (Sandbox Code Playgroud)

我将在这样的json数组中得到所有响应

JSONObject js =new JSONObject(response);
routeJsonArray.=js.getJSONArray("data");
Run Code Online (Sandbox Code Playgroud)

但我需要反转数据数组内的所有对象.换句话说,当我得到响应并打印commant_id"43906","43905"时,

但我需要反转那些物体,这样当我打印它时首先给出"43905","43906",

有迭代的解决方案i = routeJsonArray.length; i > 0; i--但我不想要这个.我想将反向数组存储在另一个数组中..

我试着这样.

String [] routeStationString;

JSONArray localJsonArray = js.getJSONArray("data");
routeStationString = new String[localJsonArray.length()];
int k = 0;
for (int i = localJsonArray.length(); i > 0; i--) {
    routeStationString[k++] = localJsonArray.getJSONObject(i);
}
System.out.println(routeStationString);
Run Code Online (Sandbox Code Playgroud)

它给出了错误.

Pav*_*los 5

我的方法是创建一个表示数组注释的Java模型,然后像这样继续.

ArrayList<Comment> mList = new ArrayList<Comment>();

for(int i=0;i<routeJsonArray.length();i++){
    //get the jsonobject based on the position
    //retrieve its values
    //create a new comment object and store it to the mList
}

Collection.reverse(mList);
Run Code Online (Sandbox Code Playgroud)