OutputStream out = null ;
HashMap<String, Object> jsonMap = new HashMap<>();
//xmxxList 是要转成json格式的数据
jsonMap.put("xmxx",xmxxList);
String jsonString = JSON.toJSONString(jsonMap, SerializerFeature.WriteMapNullValue);
try {
out = response.getOutputStream();
response.addHeader("Content-disposition","attachment;filename="
+java.net.URLEncoder.encode("json.json","utf-8"));
Writer writer = new OutputStreamWriter(out);
writer.write(jsonString);
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}finally {
if(out!=null){
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}