Check and read the internal json array that is in the main json array in android?

I want to check and read the JSON array that is in the main JSON array.

How to check if the main jsonarray has an array of submenus that I want to read?

I implemented my code here, but it does not give me a value in an array of submenus:

for (int i = 0; i < jarray.length(); i++) { listDataHeader.add(jarray.getJSONObject(i).get(ClassVariable.MENU.TITLE).toString()); // For Getting Main Menu in ArrayList String title = jarray.getJSONObject(i).get(ClassVariable.MENU.TITLE).toString(); String uid = jarray.getJSONObject(i).get(ClassVariable.MENU.UID).toString(); String pid = jarray.getJSONObject(i).get(ClassVariable.MENU.PID).toString(); HashMap<String,String> map = new HashMap<String, String>(); map.put(ClassVariable.MENU.TITLE, title); map.put(ClassVariable.MENU.UID, uid); map.put(ClassVariable.MENU.PID, pid); headerarraylist.add(map); if (jarray.getJSONObject(i).has(ClassVariable.SUBMENU.SUBMENU)) { JSONArray jarraysubmenu = jarray.getJSONObject(i).getJSONArray(ClassVariable.SUBMENU.SUBMENU); Log.e("JarraySubmenu","----->" + jarraysubmenu); } } 

screenshot of sample JSON

+1
source share
1 answer

How to check if the main jsonarray has a submenu array that I want to read?

Here you will find:

 JsonArray jarr = jarray.getJSONObject(i).optJSONArray(ClassVariable.SUBMENU.SUBMENU); if(jarr.length()>0 && jarr!=null) { SUBMENU Jarray is present } else { SUBMENU Jarray is Not present } 
0
source

Source: https://habr.com/ru/post/949545/


All Articles