This question already has an answer here:
- How to loop through JSON array? 8 answers
I am using java.
I have pasted below response for reference. I need to loop the below JSON Array response.
I can able to get the full response. But, I need to access the device Type first for example:deviceType=android and then using that device type I need to get the id of that particular device type for example: id=16.
Response: { "BannerConfigurations": [ { "id": 16, "partnerId": 69, "appId": "28470216", "affiliateData": "", "status": true, "deviceType": "ios", "daysHidden": 15, "daysReminder": 30 }, { "id": 161, "partnerId": 69, "appId": "com.android.news", "affiliateData": "", "status": true, "deviceType": "android", "daysHidden": 15, "daysReminder": 30 } ] }
JSON is a Serialization Format. This means you should rarely analysis JSON directly.
The typical pattern would be to deserialize the JSON into Java objects and then use those in your analysis. Maybe even using a object query API such as QueryDSL on the resulting Collection for example.
I'm assuming you are starting with the full JSONObject but you can skip the first line if you've for the banner configurations array.
first create a class called
Devices
that contains setters and getters for all of the device attributes and a constructor "contract class"then in your main class "Activity" define an instance:
then in your
AsyncTask
->onPostExecute()
method write down this code:then loop around the data: