ssh中list轉化成json讓微信小程式接收
方法一
其中list為傳過來的集合(但是方法一會產生中文亂碼)
public void outt(List<Student> list){
HttpServletResponse response=ServletActionContext.getResponse();
try {
response.setCharacterEncoding("UTF-8");
PrintWriter out= ServletActionContext.getResponse().getWriter();
out.print(json);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
方法二
其中list為傳過來的集合(不會中文亂碼) public void outt(List<Student> list){
HttpServletResponse response=ServletActionContext.getResponse();
try {
JSONArray json=JSONArray.fromObject(list);
response.setContentType("text/html; charset=UTF-8");
response.getWriter().print(json);
System.out.println(json);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}