使用讀卡器:
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
StringBuilder sb = new StringBuilder();
BufferedReader reader = request.getReader();
try {
String line;
while ((line = reader.readLine()) != null) {
sb.append(line).append('\n');
}
} finally {
reader.close();
}
System.out.println(sb.toString());
}
,或者你可以嘗試使用庫解析來自請求對象的JSON,一個例子是 org.json它可以爲你做到這一點很容易....這裏是一些樣本代碼讓你開始:
import org.json.*;
JSONObject obj = new JSONObject(" .... ");
String pageName = obj.getJSONObject("pageInfo").getString("pageName");
JSONArray arr = obj.getJSONArray("posts");
for (int i = 0; i < arr.length(); i++)
{
String post_id = arr.getJSONObject(i).getString("post_id");
......
}
下載JAR:http://mvnrepository.com/artifact/org.json/json
來源
2017-09-28 16:28:02
Moe