处理Struts2的action中对返回的json在另一端接收乱码问题
2014-09-13 18:44
423 查看
private JSONObject result;
private IAppService ssuAppService;
public String getApps(){
logger.info("OuterInterfaceAction getApps()..start" );
result = new JSONObject();
try {
List<App> listApp = ssuAppService.getAppList();
if(null==listApp||listApp.size()<1){
result.put("returnCode", "10");
result.put("returnMsg", "app不存在");
return SUCCESS;
}
JsonConfig jsonConfig = new JsonConfig(); //建立配置文件
jsonConfig.setIgnoreDefaultExcludes(false);
jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
jsonConfig.setExcludes(new String[]{"deviceType","className","entityDescription","objectDescription","objectID","objectName"}); //jsconfig 设置过滤属性
result.put("returnCode", "00");
result.put("returnMsg", "认证成功");
result.put("extraInfo", JSONArray.fromObject(listApp, jsonConfig).toString());
//处理编码开始
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=GBK");//转换成你需要接收字符的编码
response.getWriter().write(result.toString());
response.getWriter().flush();
response.getWriter().close();
//转码结束
return SUCCESS;
} catch (Exception e) {
result.put("returnCode", "-1");
result.put("returnMsg", "认证失败,接口发生异常");
e.printStackTrace();
return SUCCESS;
}
}
private IAppService ssuAppService;
public String getApps(){
logger.info("OuterInterfaceAction getApps()..start" );
result = new JSONObject();
try {
List<App> listApp = ssuAppService.getAppList();
if(null==listApp||listApp.size()<1){
result.put("returnCode", "10");
result.put("returnMsg", "app不存在");
return SUCCESS;
}
JsonConfig jsonConfig = new JsonConfig(); //建立配置文件
jsonConfig.setIgnoreDefaultExcludes(false);
jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
jsonConfig.setExcludes(new String[]{"deviceType","className","entityDescription","objectDescription","objectID","objectName"}); //jsconfig 设置过滤属性
result.put("returnCode", "00");
result.put("returnMsg", "认证成功");
result.put("extraInfo", JSONArray.fromObject(listApp, jsonConfig).toString());
//处理编码开始
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=GBK");//转换成你需要接收字符的编码
response.getWriter().write(result.toString());
response.getWriter().flush();
response.getWriter().close();
//转码结束
return SUCCESS;
} catch (Exception e) {
result.put("returnCode", "-1");
result.put("returnMsg", "认证失败,接口发生异常");
e.printStackTrace();
return SUCCESS;
}
}
相关文章推荐
- Struts2 学习笔记 —— 10 —— Action接收参数时的中文乱码问题
- struts2中action实现ModelDriven后无法返回json的问题
- JavaScript传中文值给Action出现乱码问题解决和返回ajax 返回 输出 json 乱码
- Struts2 Action接收中文乱码问题
- javascript 处理返回json中的\u中文乱码问题(也不是乱码了,就是\u编码)
- struts2 action接收到的参数中文乱码的问题
- 处理SpringMVC返回json乱码问题
- Struts2的action中处理JSONP方式提交的中文乱码问题:
- Jquery跨域调用struts2的Action返回json数据易出现的问题
- Jquery跨域调用struts2的Action返回json数据易出现的问题
- Struts2Action使用插件返回json时报错问题
- action接收到来自jsp页面的请求时出现中文乱码问题处理方法
- SpringMVC3.2 处理Ajax请求时返回json字符串的中文乱码问题
- 一般处理程序返回的json数据,前台接收不到问题
- Android,Post请求返回乱码问题的处理方式
- Struts1 处理接收参数插入到数据库之后呈乱码的问题解决
- struts2中form提交到action中的中文参数乱码问题解决办法(包括取中文路径)
- jquery-autoComplete 处理返回的json对象问题
- Struts2一个Action内包含多个请求处理方法的处理,method的使用方法,struts2中的路径问题,通配符映射
- struts2的action中返回json格式的数据