Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7766245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:21:56+00:00 2026-06-01T15:21:56+00:00

I;m trying to parse a json string which I receive from web server as

  • 0

I;m trying to parse a json string which I receive from web server as a response, but I have a strange issue. In my json I have a few JSONObjects, which I never know what will be their names and I should cycle them depending on how much keys it has. But the problem is with the code I’m using it’s getting the same value everytime even when I know that there is other values too.

Here is the cod which I’m using :

JSONObject json = (JSONObject) new JSONTokener(jsonBuffer).nextValue();


        JSONObject country = json.getJSONObject(String.valueOf(json.keys().next()));
        Iterator<Object> keys = json.keys();
        while (keys.hasNext()) {


            String countryName = country.getString("country_name");
            Log.e("","country_name: "+countryName);

            String data = country.getString("data");
            Log.e("","data : "+data);
        }

and here is what my json looks like :

"AZ": {
    "country_name": "Azerbaijan",
    "data": {
        "181261": {
            "time_published": "2012-04-04 15:55:29",
            "title": "Azerbaijan, Turkey not to change stakes in TANAP",
            "body": null
        },
        "181260": {
            "time_published": "2012-04-04 15:53:10",
            "title": "SOCAR mulls acquisition of Swiss refinery",
        },
        "181061": {
            "time_published": "2012-04-03 05:53:00",
            "title": "Azerbaijan, Lithuania mull LNG terminal investment",
        },
        // and so on....
    }
}, // and it keeps going on 

Any ideas how my jsonParser should looks like?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:21:57+00:00Added an answer on June 1, 2026 at 3:21 pm

    I’m not very familiar with Android and Java, but I assume it should be:

    // parse JSON
    JSONObject json = (JSONObject) new JSONTokener(jsonBuffer).nextValue();
    
    // get all keys (they are probably strings)
    Iterator<String> keys = json.keys();
    
    // as long as there are more keys
    while (keys.hasNext()) {
        // get the object corresponding to the next key
        JSONObject country = json.getJSONObject(keys.next());
    
        String countryName = country.getString("country_name");
        Log.e("","country_name: "+countryName);
    
        String data = country.getString("data");
        Log.e("","data : "+data);
    }
    

    From my comments:

    It looks to me that you have an endless while loop, it actually never gets out to assign a new value to country.

    You have to iterate over all keys, get the country object for the key, and then access it’s values.

    Currently you are getting the first country element, get the keys and just check whether the iterator contains keys. But you are not advancing the iterator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to parse a JSON response from a server using javascript/jquery. This
I am trying to parse a string which in JSON format only that keys
I’m new to android,I have an activity class which fetches Json string from url
I have json which I am trying to parse using Jackson. JSON looks as
I'm trying to deserialize json data services recieved from a web server into an
Below is my json string, which i am trying to parse to list of
I'm trying to parse a JSON string in Java but I cant figure out
I am trying to echo a json string in PHP which retrieves data from
I am trying to parse the following JSON string remotely: [{name:Object1,data:[1,2]},{name:Object2,data:[3,4]}] I am doing
I am trying to parse the json values from the following stream: {id: tag:search.xxxxx.com,2005:xxxxxxxxxxx}

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.