怎么将jsp页面的数据转换成json格式的数据呢?
用ajax可以转换。
jsp页面的数据转换成json格式可以采用js来解析,bookList = new ArrayList<Books>JSONObject json = new JSONObjectjson.accumulate("bookList", bookList);
json.accumulate("pageNum", pageNum);
json.accumulate("totalPages", totalPages);
json.accumulate("totalNum", totalNum);
jsonObj = json.toString();
jsonObj = {"totalNum":5,"bookList":[{"catGrade":null,"sourceCat":"xx","catProseries":"yy"}, {"catGrade":null,"sourceCat":"yy","catProseries":"xx"}],"totalPages":3,"pageNum":2}
function(data){//回调函数
var json = eval("("+data+")"); //将数据转换成json类型var bookList = json.bookList ;
alert(bookList[0].catGrade);
2016-01-08 · 做真实的自己 用良心做教育
例如在ation中:
bookList = new ArrayList<Books>();
JSONObject json = new JSONObject();
json.accumulate("bookList", bookList);
json.accumulate("pageNum", pageNum);
json.accumulate("totalPages", totalPages);
json.accumulate("totalNum", totalNum);
jsonObj = json.toString();
jsonObj = {"totalNum":5,"bookList":[{"catGrade":null,"sourceCat":"xx","catProseries":"yy"}, {"catGrade":null,"sourceCat":"yy","catProseries":"xx"}],"totalPages":3,"pageNum":2}
js部分:
function(data){//回调函数
var json = eval("("+data+")"); //将数据转换成json类型
//此处获取
var bookList = json.bookList ;
alert(bookList[0].catGrade);
}
哦哦,真的非常感谢。