0

I'm trying to get json value form api. There is one object key that is dynamic so how can I solve it?

I got json data as like in the picture.

enter image description here there is the numbers after "pages" that numbers are randomly changing and so how can I get that object value?

4
  • Please post your json. Commented Mar 8, 2014 at 15:38
  • get the "pages" object and iterate over the keys. For each key, get its object. Commented Mar 8, 2014 at 15:40
  • I call like this. jsonObject.getJSONObject("10243236") but that key number is changing. Commented Mar 8, 2014 at 15:43
  • but you can get the keys... Commented Mar 8, 2014 at 15:43

1 Answer 1

2

Do current JSON String Parsing as:

   JSONObject jObject = new JSONObject("your json String");
   JSONObject jObjquery = jObject.getJSONObject("query"); // get query JSONObject
   JSONObject jObjpages = jObjquery.getJSONObject("pages");//get pages JSONObject
   // get dynamic keys from pages object
            Iterator<?> keys = jObjpages.keys(); 

     while( keys.hasNext() ){
        String key = (String)keys.next();
        if( jObjpages.get(key) instanceof JSONObject ){
           // get all values from JSONObject
           String str_pageid=jObjpages.optString("pageid"); 
         //get  ns, title, extract,.. in same way from jObjpages 
        }
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Yes I'm trying. Thank you.

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.