2013-04-27 55 views
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(); 

感谢

+3

JSONs是无序的:http://stackoverflow.com/a/4920304/1850609。这可能有所帮助:http://stackoverflow.com/a/6993892/1850609 – acdcjunior 2013-04-27 15:26:45

回答

2

JSON是一个无序的数据格式,你需要将接收到数据后再次进行排序。