How to get a list of all json array tag names in json object in android / java

I have a little problem parsing a json response, because it keeps updating constantly whenever I submit a request. All the examples I've seen force us to provide a tag name. My question is that I am trying to parse the data from a request sent through the API, and I want to list all the tags of all the JSON arrays that exist in the JSON object before I start the parsing. Is this possible in android. http://api.yamgo.tv/channel?apiKey=187abeefc53f900600dc0fc5b8f913a0&token=892e069fa48eead5e7f84cddafe7f0ba This is the request I am sending and it gives me a json response. which has channels as a json object and inside it are many json arrays with tags such as bollywood, entertainment, music, etc. Use the online parser to respond to check it. I want this list of array names. How can I do it. Can anyone help. Thanks.

+1
source share
2 answers

I really understood this with a little help from my friend. You must use an Iterator object. Here is a snippet of code

JSONObject channels = jobj.getJSONObject(TAG_CHANNELS); Iterator<?> keys=channels.keys(); while( keys.hasNext() ) { String key = (String)keys.next(); Log.e("Key", key); if( channels.get(key) instanceof JSONArray ){ jsontags.add(key); } } 
+6
source

Where jsonObj is a JSONObject that contains some data. According to this following code, you can only get field names, if you want for column values, then you can add additional values ​​for keys.

 List<String> listArray = new ArrayList<String>(); Iterator iter = jsonObj.keys(); int count=0; while(iter.hasNext()){ listArray.add((String)iter.next()); count +=1; } System.out.println(listArray); output: [projector, video_conference, polycom, lcd, digital_phone, speaker_phone] 
+1
source

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


All Articles