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(); }
  • 相关阅读:
    VisualVM工具的使用
    jstack的使用
    JVM内存溢出的定位与分析
    初识JVM
    JVM运行参数
    VIM 常用命令
    python3 简单抓取图片2
    python3 抓取图片
    node.js GET 请求简单案例
    node.js 爬虫
  • 原文地址:https://www.cnblogs.com/2sheep2simple/p/10626817.html
Copyright © 2011-2022 走看看