Estou usando a biblioteca Java APACHE HTTP, eu faço uma requisição e recebo um JSON como resposta. Daí, preciso extrair alguns dados, mas não entendi muito bem como posso fazer isso. A forma que tenho hoje é a seguinte:
class SenderPost {
private HttpResponse response;
Integer postLogin(String login, String password) throws UnsupportedEncodingException {
DOMSenderLogin dsl = new DOMSenderLogin(login, password);
Gson gson = new Gson();
String jsonToSend = gson.toJson(dsl);
HttpClient client = HttpClientBuilder.create().build();
CloseableHttpClient clientClose = HttpClients.createDefault();
HttpPost post = new HttpPost("some_url");
StringEntity entity = new StringEntity(jsonToSend);
post.setHeader("Accept", "application/json");
post.setHeader("Content-Type", "application/json");
post.setHeader("Authorization", "Bearer aReallyReallyNiceBearer");
post.setEntity(entity);
try {
response = client.execute(post);
HttpEntity entidade = response.getEntity();
String responseString = EntityUtils.toString(entidade, "UTF-8");
System.out.println(responseString);
clientClose.close();
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Não foi possível se conectar aos servidores", "error", JOptionPane.INFORMATION_MESSAGE);
}
post.releaseConnection();
return response.getStatusLine().getStatusCode();
}
}
E eu consigo a resposta em formato de String, em exemplo:
{"id":145,"login":"o_login","email":"someEmail@some.com","descricao":"Operador","idioma":"pt-BR","timezone":"America\/Sao_Paulo"}
O que posso fazer para conseguir pegar os dados dessa string?
Bibliotecas que estou usando: APACHE HTTPCLIENT, GSON