0
我使用json-simple來寫json。 和我的sql查詢我使用按時代desc順序。但簡單的json正在重新排列所有內容,而且我無法在我的jquery中以正確的順序閱讀。 我該如何阻止?simple-json正在洗牌我的數據
JSONObject obj = new JSONObject();
while (rs.next()) {
Long epoch = rs.getLong(4);
String data = new java.text.SimpleDateFormat("dd/MM/yyyy").format(new java.util.Date(epoch * 1000));
String hora = new java.text.SimpleDateFormat("HH:mm:ss").format(new java.util.Date(epoch * 1000));
JSONObject sub = new JSONObject();
sub.put("id", rs.getInt(1));
sub.put("idUser", rs.getInt(2));
if ("".equals(name)) {
sub.put("user", user.getNameById(rs.getInt(2)));
} else {
sub.put("user", name);
}
sub.put("recado", rs.getString(3));
sub.put("epoch", rs.getLong(4));
sub.put("data", data);
sub.put("hora", hora);
obj.put(rs.getInt(1), sub);
}
return obj.toJSONString();
感謝
JSONs是無序的:http://stackoverflow.com/a/4920304/1850609。這可能有所幫助:http://stackoverflow.com/a/6993892/1850609 – acdcjunior 2013-04-27 15:26:45