jQuery 如何使用 JSON 从 Wikipedia API 检索数据?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16735437/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to retrieve data from Wikipedia API using JSON?
提问by Rushikesh jogle
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/
回答by
Use the following code to get the data:
使用以下代码获取数据:
$.getJSON(playListURL ,function(data) {
$.each(data.query.pages, function(i, item) {
alert(item.title);
});
});
回答by vinothini
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.
像这样,您也可以采用修订值。
回答by Milind Anantwar
It should be data.query.pages
instead of data.pages
它应该data.query.pages
代替data.pages