jsp JSON使用

来源:互联网 发布:比较好用的vpn 知乎 编辑:程序博客网 时间:2024/05/21 13:22
把jsp程序中信息输出到页面并解析!本例为ajax访问
  
/**********Java类***************/
importnet.sf.json.JSONObject;
  
JSONObject beanJSON =new JSONObject();
  
beanJSON.put("user","张三");
beanJSON.put("time","2000-1-1");
beanJSON.put("content","hello word!");
  
response.getWriter().print(beanJSON);// 输出
  
/**********页面js部分***************/
var tt=eval("("+ resultText + ")");//resultText 为ajax返回值,
alert(tt.user);
alert(tt.time);
alert(tt.content);
原创粉丝点击