Wikipedia Viewer JSON

Wikipedia Viewer JSON
0

#1

I’m trying to work through the JSON results of the Wikipedia API and output the relevant data, but I’m having a lot of trouble finding what I want in the JSON. I’ve tried using a FOR X IN Y loop, but I just get a list of numbers with no other internal structure. I can’t seem to work my way into the appropriate level of the JSON. If anyone has a chance to look at the Codepen and give me some advice, I’d really appreciate it.


#2

try foreach, check the structure of what you get by simply opening the url you request in the browser like https://en.wikipedia.org/w/api.php?origin=*&action=query&utf8&list=search&format=json&srsearch=horse you get the stringified json

the following instead of your success function works btw, types out the list of results and the snippets of text in the console

    success: function(data) {
      data.query.search.forEach( function(q) {
        console.log(q.title);
        console.log(q.snippet);       
      });

#3

Thanks. I confess I searched around and looked at someone else’s code. I don’t know exactly how I was misinterpreting the JSON, but I think I understand how to loop through it now.