问题描述
- 为什么得不到后台传的JSON数据?
-
求帮助啊
Springmvcpublic void firstP(HttpServletRequest request) { List<Picture> pl = (List<Picture>) pageService.getPageList(1, number); JSONArray array = JSONArray.fromObject(pl); request.setAttribute("pl",array.toString()); System.out.println(array.toString()); request.setAttribute("user", "user"); }
js:
能得到user,
<script> var pl = eval('('+"${pl}"+')'); var u = "${user}"; document.getElementById("show").innerHTML=pl[0].pid; </script>
后台打印的JSON:
[{"category":{"cid":2,"sort":"B"},"pdescribe":"BBB","pid":2,"pres":"333","psize":"bbb","purl":"bbb"},{"category":{"cid":3,"sort":"C"},"pdescribe":"ddd","pid":3,"pres":"333","psize":"ddd","purl":"ddd"},{"category":{"cid":1,"sort":"A"},"pdescribe":"eee","pid":4,"pres":"444","psize":"eee","purl":"eee"},{"category":{"cid":2,"sort":"B"},"pdescribe":"fff","pid":5,"pres":"fff","psize":"fff","purl":"ddd"}]
解决方案
json后台向前台传数据
json 后台传数据到前台
jquery解析后台传的json数据
解决方案二:
pl session存储对象序列化为json的字符串,而不是直接对象
http://www.docin.com/p-587238555.html
要不调用默认的toString得到的不是你那个字符串,你自己看客户端源代码就知道了
解决方案三:
将${pl}用变量存起来,var pp = "${pl}";var pl = eval('('+pp+')');这样试试
解决方案四:
可以看看 前阿泰选择接受的数据类型是什么样的
时间: 2024-09-20 20:06:41