如何把数据转换成json格式
2个回答
展开全部
jsp页面的数据转换成json格式可以采用js来解析:
例如在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);
}
例如在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);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询