1

I have a small problem parsing json response because it constantly keeps on getting updated whenever i send a request.All the examples I have seen makes us provide the tag name. My question is that I am trying to parse data from a request sent through an API and I want to list out all the tags of all JSON Arrays existing within a JSON Object before I start parsing. Is it 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 within it many json arrays with tags like bollywood, entertainment, music,etc. Use an online parser for the response to check it out. I want this list of array names. How can I do it. Could anyone please help. Thanks.

3
  • There is some mistake in above link because this is giving me null pointer exception. Commented Sep 20, 2012 at 8:52
  • In Dom Parsing this is giving me error of null pointer exception before parse any tag. Commented Sep 20, 2012 at 9:55
  • ok i guess there may be a need to change the apikey and token so thats why u are getting the error and I figured to get it done using Iterator. posting the solution shortly. Commented Sep 20, 2012 at 9:59

2 Answers 2

6

I actually figured it out with a small help from one of my friend. Needed the use of Iterator object. Here is the 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);
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

1

Where jsonObj is the JSONObject which contains some data, By these following code you can get only field names, if u want for column values then you can add further for value 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]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.