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

  • Home
  • SEARCH
  • 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 302985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:08:50+00:00 2026-05-12T07:08:50+00:00

I use this code to gathering the information from Wiki: http://en.wikipedia.org/w/api.php?action=query&rvprop=content&prop=revisions&format=json&titles=apple And I can

  • 0

I use this code to gathering the information from Wiki:

http://en.wikipedia.org/w/api.php?action=query&rvprop=content&prop=revisions&format=json&titles=apple

And I can get a JSON String like this

{
    "query": {
        "normalized": [{
            "from": "apple",
            "to": "Apple"
        }],
        "pages": {
            "18978754": {
                "pageid": 18978754,
                "ns": 0,
                "title": "Apple",
                "revisions": [{
                    "*": "Something....."
                }]
            }
        }
    }
}

I can eval it to JSON, but the problem is, I can get into the query>pages, after that I can’t get deeper, it was Because the Wiki API return me as a String 18978754, but it can’t get the value by this:

jsonObject.query.pages.18978754

Some assumption I need to clarify, I don’t know the number 18978754. Do I need to get the number first or I can still get “Something…” within knowing the number.

  • 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-05-12T07:08:50+00:00Added an answer on May 12, 2026 at 7:08 am

    What about using array-syntax :

    jsonObject.query.pages[18978754]
    

    Seems to be working, using firebug :

    >>> data.query.pages[18978754]
    Object pageid=18978754 ns=0 title=Apple revisions=[1]
    

    And :

    >>> data.query.pages[18978754].title
    "Apple"
    

    Note accessing data-object with an array-syntax is also possible for the other properties ; for instance :

    >>> data['query'].pages[18978754].title
    "Apple"
    

    That’s perfectly valid JS syntax 🙂


    Added after seing the comment / edit

    If you don’t know the ids of the pages, you can iterate over the pages, with something like this :

    for (var pageId in data.query.pages) {
        if (data.query.pages.hasOwnProperty(pageId)) {
            console.log(data.query.pages[pageId].title);
        }
    }
    

    Note that I’m using hasOwnProperty to be sure the object I’m on has the property, and that it’s not coming from any kind of inheritance or anything like that :

    Every object descended from Object
    inherits the hasOwnProperty method.
    This method can be used to determine
    whether an object has the specified
    property as a direct property of that
    object; unlike the in operator, this
    method does not check down the
    object’s prototype chain.

    Depending on what’s in “revision“, you might have to do the same on that one too, btw…

    Hope this helps better 🙂


    Second edit, after second set of comments :

    Well, going a bit farther (didn’t think you meant it literally) :

    data.query.pages[pageId].revisions
    

    is an array (note the [] symbols) that seems to be able to contain several objects.

    so, you can get the first one of those this way :

    data.query.pages[pageId].revisions[0]
    

    The second one this way :

    data.query.pages[pageId].revisions[1]
    

    (there is no second one in the example you provided, btw — so this is in theory ^^ )

    And so on.

    To get everyone of those objects, you’d have to do some kind of loop, like this :

    var num_revisions = data.query.pages[pageId].revisions.length;
    var i;
    for (i=0 ; i<num_revisions ; i++) {
        console.log(data.query.pages[pageId].revisions[i]);
    }
    

    And now, inside that loop, you should be able to get the ‘*’ property of the given object :

    data.query.pages[pageId].revisions[i]['*']
    

    So, the final code becomes :

    for (var pageId in data.query.pages) {
        if (data.query.pages.hasOwnProperty(pageId)) {
            var num_revisions = data.query.pages[pageId].revisions.length;
            var i;
            for (i=0 ; i<num_revisions ; i++) {
                console.log(data.query.pages[pageId].revisions[i]['*']);
            }
        }
    }
    

    Using this code in firebug, I now get the literral sting you’re looking for :

    Something.....
    

    Of course, you could probably just use :

    for (var pageId in data.query.pages) {
        if (data.query.pages.hasOwnProperty(pageId)) {
            console.log(data.query.pages[pageId].revisions[0]['*']);
        }
    }
    

    Which will work fine if you always want to deal with only the first element of the revisions array.

    Just beware : in your example, there was only one revision ; the code I provided should be able to deal with many ; up to you to determine what you want to do with those 😉

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

Sidebar

Related Questions

If I wrote this code: typeof(myType).TypeHandle Would it use reflection? How much different from:
i am trying to use this code to bind my asp.net menu control to
I often use this code pattern: while(true) { //do something if(<some condition>) { break;
I'm trying to use this code to replace spaces with _, it works for
Consider: print $foo, AAAAAAAA, $foo, BBBBBBBB; Let's say I want to use this code
I'm looking at some GXT code for GWT and I ran across this use
What criteria should I use to decide whether I write VBA code like this:
In C# I use the #warning and #error directives, #warning This is dirty code...
I use this tool called Lazy C++ which breaks a single C++ .lzz file
I use this line in my .htaccess file to automatically add a trailing slash

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.