我在action中写了下面的一个方法
[code="java"]
public String getDepartmentList() {
try {
List list = userService.getDepartments();
StringBuilder sb = new StringBuilder();
sb.append("{").append(" \"total \" : ").append(list.size()).append(",").append(" \" row \" :[");
for(Departmenet department : list){
sb.append("{ \" department_name \" :").append(" \" ").append(department.getDepartmentName()).append(" \" ,")
.append(" \" id \" :").append(" \" ").append(department.getId()).append(" \" },");
}
sb.deleteCharAt(sb.length()-1);
sb.append("]}");
result = sb.toString();
System.out.println(result);
return this.SUCCESS;
} catch (Exception e) {
e.printStackTrace();
addActionError(e.getMessage());
}
return this.INPUT;
}
[/code]
在运行时 tomcat打印出来的日志是正确的:
[code="java"]{"total":2,"row":[{"department_name ":"开发部","id":"1"},{"department_name ":"销售","id":"2"}]}[/code]
而我用浏览器直接访问url的时候显示的是:
[code="java"]"{ \"total \" : 2, \" row \" :[{ \" department_name \" : \" 开发部 \" , \" id \" : \" 1 \" },{ \" department_name \" : \" 销售 \" , \" id \" : \" 2 \" }]}"[/code]
请问下着是什么原因造成了 为什么转义符被打印出来了