0
I have a Json that does not contain an array and I need to get information from this Json. Follows the JSON
{"_status":"sucesso","_mensagem":"Impressão em processamento","_dados":{"situacao":"PROCESSANDO","protocolo":"BkVglXYWQ"}}
What I’ve tried to do so far
JsonReader jsonReader = Json.createReader(new StringReader(jsonProtocolo));
JsonObject jsonObject = jsonReader.readObject();
JsonObject attributeDados = jsonObject.getJsonObject("_dados");
JsonArray jsonArray = attributeDados.getJsonArray("_sucesso");
String numeroProtocolo = jsonArray.getJsonObject(0).getString("protocolo");
System.out.println("NUMERO PROTOCOLO: " + numeroProtocolo);
But I get nullPointer in the line String numeroProtocolo = jsonArray.getJsonObject(0). getString("protocol"); I tried that way too
JSONObject obj = new JSONObject(jsonProtocolo);
String numeroProtocolo = obj.getString("protocolo");
System.out.println("NUMERO PROTOCOLO: " + numeroProtocolo);
However I get the error: Jsonobject["protocol"] not found
maybe this link can help you: http://theoryapp.com/parse-json-in-java/
– Um Programador
Thanks for the reply friend, I tried so more unsuccessfully, I will update the question with the code I tried
– Leandro Santos
I was able to solve thus Jsonobject obj = new Jsonobject(jsonProtocolo); String numeroProtocolo = obj.getJSONObject("_data"). getString("protocol");
– Leandro Santos
yes, I was writing to do so as an answer =)
– Um Programador