Steven Mark Steven Mark - 21 days ago 6
JSON Question

codenameone display entire json response message not just a single node

I am calling a parcel tracking json service using codenameone java code.
Here is the full json response:

{
"success": true,
"results": {
"tracking_reference": "DY954563460NZ",
"message_id": "682c9b69-7f90-48c6-a36d-3b371e203a96",
"message_datetime": "2016-11-11T08:08:05.0000000Z",
"service": "",
"carrier": ""
}
}


I would like to create a popup that displays the entire response - but all the examples I can see only show how to get the results node.
Here is what I am currently showing:

"results": {
"tracking_reference": "DY954563460NZ",
"message_id": "682c9b69-7f90-48c6-a36d-3b371e203a96",
"message_datetime": "2016-11-11T08:08:05.0000000Z",
"service": "",
"carrier": ""
}


This is because I am using this code to get this specific branch:

Object responseMessage = null;
responseMessage = apiResponse.get("results");
Dialog d = new Dialog("Response");
d.setScrollable(true);
d.show("Response Message", responseMessage.toString(), "OK", null);


According to this website there is a special node called 'root' which should do the trick but it errors out.

https://www.codenameone.com/javadoc/com/codename1/io/JSONParser.html

Any idea how I can display the entire response message?
Thanks

Answer

Remove this line:

responseMessage = apiResponse.get("results");
Comments