// json测试 接收一个json串
StringBuffer sb = new StringBuffer();
BufferedReader br = new BufferedReader(
new InputStreamReader((ServletInputStream) request.getInputStream(), "utf-8"));
String temp;
while ((temp = br.readLine()) != null) {
sb.append(temp);
}
br.close();
System.out.println(sb.toString());
// 返回json数据
response.setContentType("application/x-javascript; charset=utf-8");
PrintWriter pw = response.getWriter();
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("name", "aaa");
System.out.println(jsonObject.toString());
pw.write(jsonObject.toString());
pw.flush();
pw.close();
java-web-接收json串
Author: tea9
Permalink: http://tea9.github.io/post/816646297.html
License: Copyright (c) 2017-2025 CC-BY-NC-4.0 LICENSE
Slogan: Do you believe in DESTINY?