Json 学习笔记
2011-05-18 12:14
120 查看
java后端处理
Json格式相对XML一种轻量级的返回结果。
如何将Java对象封装为Json格式,以下是一个Demo。
当输出到页面时默认是text/html格式,对contextType需要修改为text/xml,如果需要进行编码,也需要对charset进行修改。
具体方法:
HttpServletResponse response = runData.getResponse();
response.setContentType("text/xml;charset=UTF-8");
response.getWrite().write(jsonStr);
alter table cps_group_keeper_relation drop constraint UK_CPS_GROUP_KEEPER_RELATION
前段页面处理
Json格式相对XML一种轻量级的返回结果。
如何将Java对象封装为Json格式,以下是一个Demo。
import net.sf.json.JSONArray; import net.sf.json.JSONObject; class Test{ public static void main(String [] args){ JSONObject obj = new JSONObject(); GroupKeeperJSON do1 = new GroupKeeperJSON(); do1.setqID("111"); GroupKeeperJSON do2 = new GroupKeeperJSON(); do2.setqName("name"); JSONArray array = new JSONArray(); array.add(do1); array.add(do2); obj.put("list", array); Message msg = new Message(false); msg.setMessage("OKK"); obj.put("info", msg); System.out.println(obj); } }
当输出到页面时默认是text/html格式,对contextType需要修改为text/xml,如果需要进行编码,也需要对charset进行修改。
具体方法:
HttpServletResponse response = runData.getResponse();
response.setContentType("text/xml;charset=UTF-8");
response.getWrite().write(jsonStr);
alter table cps_group_keeper_relation drop constraint UK_CPS_GROUP_KEEPER_RELATION
前段页面处理
function joinAction(cID,qID,qName,type){ YUI().use('node','dialog','io',function(Y){ Y.io('${keeperModule}/market/cps_group_service.do',{ on: { success: function(id,o){ eval("var s = " + o.responseText);//处理JSON返回结果 alert(s.msg); } }, method: "GET", data: "cid="+cID+"&qid="+qID+"&act="+type+"&time=" + new Date().getTime()//加时间戳是为了防止多次打开无效 }); dialog_joinGroup.close(); }); }
相关文章推荐
- Newtonsoft.Json(Json.Net)学习笔记
- 黑马程序员_Json学习笔记整理
- PHP 开发 APP 接口 学习笔记与总结 - JSON 结合 XML 方式封装通信接口
- Spring MVC 3学习笔记+教程(三)返回JSON数据
- Spring MVC 学习笔记 json格式的输入和输出
- Spring MVC 3学习笔记+教程(三)返回JSON数据
- Python2学习笔记之gui和安装demjson库
- iOS 阶段学习第22天笔记(JSON数据格式介绍)
- Javascript学习笔记8 用JSON做原型
- Newtonsoft.Json(Json.Net)学习笔记-高级使用(转)
- Netty学习笔记之一(Netty解析简单的Http Post Json 请求)
- json学习笔记------
- extJs 2.1学习笔记(JSON序列化篇)
- 学习笔记 Tianmao 篇 使用简单封装后的自定义OkHttp 获取json被GSON解析后的数据
- Json.Net学习笔记(十) 保持对象引用
- JSON解析学习笔记(json、gson、fastjson)
- Json(Json.Net)学习笔记
- Runoob之Json学习笔记
- Spring MVC 学习笔记 json格式的输入和输出
- JavaScript高级程序设计第20章JSON 笔记 (学习笔记)