如何使用JSON从Wikipedia API检索数据?

时间:2022-09-25 23:34:25

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

这里我使用以下代码从Wikipedia获取数据。但这对我不起作用。

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/

演示链接:http://jsfiddle.net/rushijogle/dyeqy/

3 个解决方案

#1


6  

Use the following code to get the data:

使用以下代码获取数据:

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

        });
    });

#2


3  

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

演示是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


2  

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

它应该data.query。页面而不是data.pages

Working Fiddle

工作小提琴

#1


6  

Use the following code to get the data:

使用以下代码获取数据:

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

        });
    });

#2


3  

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

演示是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


2  

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

它应该data.query。页面而不是data.pages

Working Fiddle

工作小提琴