0
我有以下類從json響應中返回一個spefic字段。 這裏要求的方法是在帖子後面。我如何使用get方法做到這一點? 此外,我想用頭用Json響應獲取請求?
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost post = new HttpPost(
"");
post.addHeader("Auth-Token", authenticationValues.getAuthToken());
post.addHeader("device-id", authenticationValues.getDeviceId());
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("task", "savemodel"));
String generatedJSONString = null;
params.add(new BasicNameValuePair("code", generatedJSONString));
CloseableHttpResponse response = null;
Scanner in = null;
try {
post.setEntity(new UrlEncodedFormEntity(params));
response = httpClient.execute(post);
HttpEntity entity = response.getEntity();
in = new Scanner(entity.getContent());
while (in.hasNext()) {
JsonString += in.next();
}
EntityUtils.consume(entity);
} catch (IOException e) {
e.printStackTrace();
}
// System.out.println(JsonString);
JSONObject jsonObject = new JSONObject(JsonString);
JSONObject myResponse = jsonObject.getJSONObject("login");
Object myResponse2 = myResponse.get("loginStatus");
的System.out.println(myResponse2)GET請求;