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 8366027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:48:23+00:00 2026-06-09T12:48:23+00:00

I am a very beginner about JSON… How can I get the value of

  • 0

I am a very beginner about JSON…

How can I get the value of “3037904” from the following JSON Object in Java program?

{“query”:{“pages”:{“3037904”:{“pageid”:3037904,”ns”:0,”title”:”Kempinski”,
“categories”:[{“ns”:14,”title”:”Category:Companies established in 1897″},{“ns”:14,”title”:”Category:Hotel chains”},{“ns”:14,”title”:”Category:Kempinski Hotels”}]}}}}

I tried to

JSONObject query = json.getJSONObject("query");
int pages = query.getInt("pages");

But it takes

"{"3037904":{"pageid":3037904,"ns":0,"title":"Kempinski",
"categories":[{"ns":14,"title":"Category:Companies established in 1897"},{"ns":14,"title":"Category:Hotel chains"},{"ns":14,"title":"Category:Kempinski Hotels"}]}}}}", 

not only “3037904”.

  • 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-09T12:48:25+00:00Added an answer on June 9, 2026 at 12:48 pm

    You’ll need to do a little more work with your JSONObject.

    In this answer I’ll assume that you want to get at that pageid value.

    Let’s only assume the existence of pageid in the nesting – at a specific level:

    // "query" is the top-level object: 
    JSONObject query = json.getJSONObject("query");
    // "pages" is a field of "query"
    JSONObject pages = query.getJSONObject("pages");
    
    // these will hold the object with the value that you want, and that value:
    JSONObject nestedObject = null;
    int pageId = 0;
    
    // these are the property names in the "pages" object:
    String[] keys = pages.getNames(pages);
    
    // iterate over the keys in the "pages" object, looks for JSONObjects:
    for (int i = 0; i < keys.length; i++)
    {
        try
        {
            nestedObject = pages.getJSONObject(keys[i]);
            // only consider objects with a "pageid" key, stop at the first one:
            if (nestedObject.has("pageid"))
                break;
        }
        catch (JSONException je)
        { ; }
    }
    
    if (nestedObject != null)
       pageId = nestedObject.getInt("pageid");
    

    Your JSON input seems peculiar in that the first nested object has a pages field, that contains another object. The name in plural, pages, and the nested object – which duplicates the key containing the object as a pageid key within the object – suggests that pages should be an array of multiple such objects.

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

Sidebar

Related Questions

I am very beginner in C. I have the following structure typedef struct {
Probably a very basic beginner question. Imagine the following situation: I have an ASP.NET
This is about as beginner as a question gets, but I can't find anything
As an Objective-C beginner, I'm very confused about the init function, and how and
I am a very beginner to Java, recently trying to use some existing libraries
I'm a complete beginner in WPF so this is probably very simple. The following
I'm a beginner about Razor, and sometimes I get stuck with really simple things.
I'm very beginner for developping. environment is .. Windows XP Professional SP3 Microsoft Visual
I am very much a beginner to rails and I have a specific need
I'm very new to Objective-C, and am having some beginner issues. I have an

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.