How to retrieve data from Wikipedia API using JSON?

 ̄綄美尐妖づ 提交于 2019-12-17 19:47:07

问题


Here I am fetching the data from Wikipedia using following code. but it is not working for me.

var playListURL = 'http://en.wikipedia.org/w/api.php?format=json&action=query&titles=India&prop=revisions&rvprop=content&callback=?';

$.getJSON(playListURL ,function(data) {
    $.each(data.pages, function(i, item) {
        alert(i);
    });
});

DEMO LINK :- http://jsfiddle.net/rushijogle/dyeqy/


回答1:


Use the following code to get the data:

$.getJSON(playListURL ,function(data) {
        $.each(data.query.pages, function(i, item) {
            alert(item.title);

        });
    });



回答2:


Demo is at http://jsfiddle.net/dyeqy/3/

var playListURL = 'http://en.wikipedia.org/w/api.php?format=json&action=query&titles=India&prop=revisions&rvprop=content&callback=?';

$.getJSON(playListURL ,function(data) {
    var hash = data
    var page_value = ""
    $.each(data["query"]["pages"],function(k,v){
        alert(k)
        $.each(v,function(key,val){
          alert(key)
        });
    });
});

Like this you can take the revisions values also.




回答3:


It should be data.query.pages instead of data.pages

Working Fiddle



来源:https://stackoverflow.com/questions/16735437/how-to-retrieve-data-from-wikipedia-api-using-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!