问题一堆的一天

前端之家收集整理的这篇文章主要介绍了问题一堆的一天前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

今天碰到的问题奇奇怪怪的。。。慢慢来吧

JSONArray的用法

  1. public String select(){
  2. try {
  3. // 连接数据库
  4. /** * 将查询的信息已json的方式返回 * 并在json中添加jsonarray */
  5. Connection conn = sqlManager.newInstance().getConnection();
  6. PreparedStatement statement = conn
  7. .prepareStatement("select * from user");
  8. ResultSet set = statement.executeQuery();
  9. JSONObject obj = new JSONObject();
  10. JSONArray array=new JSONArray();
  11. set.first();
  12. while(!set.isAfterLast()) {
  13. JSONObject item = new JSONObject();
  14. item.put("username",set.getString("user_name"));
  15. item.put("password",set.getString("password"));
  16. array.add(item);
  17. set.next();
  18. }
  19. obj.put("code",0);
  20. obj.put("message","查询成功");
  21. obj.put("data",array);
  22. return obj.toString();
  23. } catch (sqlException e) {
  24. e.printStackTrace();
  25. }
  26. return null;
  27. }

猜你在找的Json相关文章