0

i'm using json-simple to write json. and on my sql query i use order by epoch desc. but simple-json is rearranging everything and i cant read in the right sequence in my jquery. how do i stop this?

        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();

thanks

  • 3
    JSONs are unordered: http://stackoverflow.com/a/4920304/1850609. Here's something that may help: http://stackoverflow.com/a/6993892/1850609 – acdcjunior Apr 27 '13 at 15:26

1 Answers1

2

JSON is an unordered data format, you need to sort again after receiving the data.

dtech
  • 13,741
  • 11
  • 48
  • 73