3
I need to convert a JSON into an object and navigate to an ID and capture only it. JSON Example:
"{"_status":"sucesso","_dados":{"_sucesso":[{"idintegracao":"BkmRboZmaaa","situacao":"SALVO","TituloNumeroDocumento":"01012020","TituloNossoNumero":"501","CedenteContaCodigoBanco":"748","CedenteContaNumero":"9999","CedenteConvenioNumero":"9999"}],"_falha":[]}}
I need to capture the idIntegration that is in _data. _success[0]. idintegracao, and save in a string. What I’ve done so far:
String jsonString = response.body().string();
JSONObject jsonObjectBoleto = new JSONObject("{" + jsonString + "}");
Iterator<String> iteratorBoletos = jsonObjectBoleto.keys();
System.out.println("TO AQUI");
System.out.println("TO AQUI NO WHILE " + iteratorBoletos.toString());
JSONObject dadosBoleto = jsonObjectBoleto.getJSONObject(iteratorBoletos.toString());
System.out.println("TO AQUI NO WHILE 2 " + iteratorBoletos.toString());
Boleto boleto = new Boleto();
System.out.println("DADOS DO BOLETO: " + dadosBoleto.getString("idintegracao"));
I tried to do it too but without success:
String jsonString = response.body().string();
String json = ("{" + jsonString + "}");
JSONObject obj1 = new JSONObject(json);
String idIntegracao = obj1.getString("idintegracao");
System.out.println("idIntegracao : " + idIntegracao);
You must have searched for libs like Jackson and Gson, and you have some specific question, don’t you? What would it be? You can post the code of what you have done so far?
– StatelessDev
Possible duplicate of Grab object inside JSON string
– StatelessDev
You already know which JSON API you will use?
– Victor Stafusa
You are using Spring Boot?
– Dherik
To generate Java classes, you can use a JSON to Java Classes generator. http://json2java.azurewebsites.net/
– Tony
I posted what I’ve done so far
– Leandro Santos