zoukankan      html  css  js  c++  java
  • js处理ajax返回的json数组

    一、json对象和json数组的区别

    jsonObject = {"name":"hey","age":18}   # json对象
    jsonArray=[{"name":"hey","age":18},{"name":"hai","age":19}]   # json数组

    二、数据处理

    前台接收到后台传过来的json数组实际上是一个字符串,字符串的内容是json数组,这种情况下先要将字符串转换成json数组,再遍历。

     $.post('/Servlet', {name:name,msg:"0"}, function (data) {
                var data = JSON.parse(data)
                alert(data[0].name)
            }) // endwith post

      #后台代码      
    BookDao bookDao = new BookDao(); try { List books = bookDao.getAllBook(name); JSONArray jsonArray = JSONArray.fromObject(books); # 将List转化成json数组传到前台 response.getWriter().println(jsonArray); } catch (SQLException e) { System.out.println("List error"); e.printStackTrace(); }
  • 相关阅读:
    <frame>、<iframe>、<embed>、<object> 和 <applet>
    xss攻击
    回流 和 重绘
    defer 和 async 的区别
    从输入URL到浏览页面的过程
    webkit vs v8
    缓存
    LeetCode
    LeetCode
    LeetCode
  • 原文地址:https://www.cnblogs.com/2sheep2simple/p/10626817.html
Copyright © 2011-2022 走看看