我得到響應這個如何在webservice響應後反轉json數組?
{
"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": [...]
}
]
}
我得到這樣
JSONObject js =new JSONObject(response);
routeJsonArray.=js.getJSONArray("data");
在JSON陣列中的所有迴應,但我需要扭轉的所有對象,它是數據數組內。在其他的字時,我得到響應和打印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);
它給出了錯誤。
使用一些IDE如Eclipse進行開發。您正嘗試將JSONObject存儲到字符串數組中。 – adwiv 2014-10-02 14:07:29