How to Get object from verticals from json android. I have got the vertical object.
JSONObject obj = new JSONObject(loadJSONFromAsset());
Log.d(String.valueOf(obj),"obj");
want other 4 which are health care environmental care agricultural product consumer product
CodePudding user response:
You can easily create Model class with response: https://www.jsonschema2pojo.org/ check this website. If you can not achieve your task then use any android studio plugin to create model classes.
CodePudding user response:
You can get JSON Objects from main object as follow:
try {
JSONObject jsonObject = new JSONObject(loadJSONFromAsset());
JSONObject verticals = jsonObject.getJSONObject("verticals");
Object healthCare = verticals.getJSONObject("Health Care");
Object envirnmentalCare = verticals.getJSONObject("Environmental Care");
Object agriculturalCare = verticals.getJSONObject("Agricultural Care");
Object consumerCare = verticals.getJSONObject("Consumer Care");
} catch (JSONException e) {
e.printStackTrace();
}