I'm working on an app that uses the wikipedia api, and i'm struggling to find the best way to interpret the results given to me by the ajax request :
The JSON I get looks like this :
{
"batchcomplete": "",
"query": {
"pages": {
"277029": {
"pageid": 277029,
"ns": 0,
"title": "Dog (zodiac)",
"index": 5,
"thumbnail": {
"source": "https://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Dog_2.svg/50px-Dog_2.svg.png",
"width": 50,
"height": 50
},
"pageimage": "Dog_2.svg",
"extract": "<p>The <b>Dog</b> (<b>狗</b>) is eleventh of the 12-year cycle of animals which appear in the Chinese zodiac related to the Chinese calendar. The <b>Year of the Dog</b> is associated with the Earthly Branch symbol <b>戌</b>. The character 狗 refers to the actual animal while 戌 refers to the zodiac animal..."
},
"552756": {
"pageid": 552756,
"ns": 0,
"title": "That Dog",
"index": 4,
"extract": "<p><b>That Dog</b> (styled as <b>that dog.</b>) is a Los Angeles-based rock band that formed in 1991 and dissolved in 1997, reuniting in 2011. The band originally consisted of Anna Waronker on lead vocals and guitar, Rachel Haden on bass guitar and vocals, her sister Petra Haden on violin and vocals..."
},
"779986": {
"pageid": 779986,
"ns": 0,
"title": "Dog Eat Dog",
"index": 7,
"extract": "<p><b>Dog Eat Dog</b> may refer to:</p>..."
},
"3279728": {
"pageid": 3279728,
"ns": 0,
"title": "Dog meat",
"index": 6,
"thumbnail": {
"source": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/20/Dog_Meat.jpg/50px-Dog_Meat.jpg",
"width": 50,
"height": 33
},
"pageimage": "Dog_Meat.jpg",
"extract": "<p><b>Dog meat</b> is the flesh and other edible parts derived from dogs. Historically, human consumption of dog meat has been recorded in many parts of the world. In the 21st century, most dog meat is consumed in China, Korea, and Vietnam, and it is still eaten or is legal to be eaten in other countries..."
}
}
}
}
I can access the pages easily using result.query.pages but thes I need to access each pages independently, without knowing what their ID will be. I thought at first, if I had to access the title of the first page for exemple, to use
query.pages[Object.keys(pages)[0]].title
But I thought it might be overly complicated. Is there a more efficient way to do it ?
Thanks a bunch !