ajax 如何返回list并且在页面迭代

 

一、假设要转换的list为:unitDetalJson

    1,在后台代码中将list变成json类型:

        JSONArray.fromObject(unitDetailList).toString()

    2,jsp的迭代代码为:

             需要中eval转换

              $.each(eval(data.unitDetalJson), function (n, value) {
              });

二、将list在后台迭代放到json里面,假设list为baseProjectList

    1,后台代码:

      getRequest().setCharacterEncoding("utf-8");
      getResponse().setCharacterEncoding("utf-8");

      JSONArray objs=new JSONArray();  

      for(int i=0;i<baseProjectList.size;i++){

               JSONObject obj=new JSONObject();            

               obj.put("text",list.get(i).get(xx));

               objs.add(obj);

      }

       getResponse().getWriter().println(objs.toString());

       2,jsp代码

       ajax({

            data.xxx

       })

你可能感兴趣的:(ajax 如何返回list并且在页面迭代)