Hi,I am trying to map a response body from an api and use that response body in my app.My API returns an array of Objects.I am using retrofit to use this response body.Still not able to use it.
I want to deserialise this data How can I do this?
I am having trouble telling if you are receiving this json on the server or in the browser. In the browser you can use eval() to turn the json into an object, then access it by using dot and array notation.
Matthew Keller wrote:I am having trouble telling if you are receiving this json on the server or in the browser. In the browser you can use eval() to turn the json into an object, then access it by using dot and array notation.
I am receiving this data in my java file(client side) of my android and then I will be pushing it into my db and fetch that data from it and display it in my xml.
posted 11 months ago
Adrian Grabowski wrote:I use org.json for this, it has JSONArray which does exactly what you want.
Already done this it is throwing error
org.json.JSONException: Not a primitive array: class java.util.ArrayList
This is the source code (or close enough) for the constructor that you are calling. It looks like you are passing-in an Object which is not an array type.
What is the type returned by response.body()? What is the class of the response object?
Ahh .. I see that you are using Retrofit. I've not used it before, but from what I see, it performs the de-serialization itself (using GSON), so there is not need to use org.json or any other library to de-serialize to your entiy objects.
Here's a simple example that I wrote to give to a quick try. It calls a service on httpbin.org which returns the HTTP headers included in the request.