这是我第一次使用AXIOS进行查询。但现在我不知道了,我希望有人能给我一个建议。
为了开发一个带有Reaction Native的词典应用程序,我想这样查询维基词典
let url = "https://en.wiktionary.org/w/api.php?format=json&action=query&titles={word}&rvprop=content&prop=revisions&redirects=1&callback=?".replace("{word}", word);
...
axios({
method: 'get',
url: url,
}).then((response) => {
var results = {
title: "",
definitions: [],
examples: []
}
....
let data = response.data;
...
此查询本身起作用...现在我想将其修改为我的目的:wiktionary-parser。
问题出现在以下位置:
if(!data || !data.query || !data.query.pages || data.query.pages[-1]) {
return callback({});
}
上面写着
TypeError: Cannot read property 'pages' of undefined
我的查询中的数据的组织方式必须不同于上面提到的维基词典解析器的这个“$.getJSON...”查询接收的数据……
但如何做到呢?
我试着和他合作
JSON.stringify(response.data)
和
JSON.parse(response.data)
我做错了什么?有什么建议吗?
先谢谢你,弗兰克
查询的完整代码为
function getENWiktionaryInfo(word, wordLanguage, callback) {
// getJSON("https://en.wiktionary.org/w/api.php?format=json&action=query&titles={word}&rvprop=content&prop=revisions&redirects=1&callback=?".replace("{word}", word), function (data) {
// $.getJSON("https://en.wiktionary.org/wiki/abdico#Latin", function (data) {
let url = "https://en.wiktionary.org/w/api.php?format=json&action=query&titles={word}&rvprop=content&prop=revisions&redirects=1&callback=?".replace("{word}", word);
console.log("getENWiktionaryInfo " + url);
axios({
method: 'get',
url: url,
}).then((response) => {
var results = {
title: "",
definitions: [],
examples: []
}
let data = response.data;
console.log("DATA "+data);
const jsonObj= JSON.stringify(response.data)
//let data = jsonObj;
var title, content;
if (!data || !data.query || !data.query.pages || data.query.pages[-1]) {
return callback({});
}
callback(results);
});
}
对(拉丁语)单词“res”的纯粹要求是:
https://en.wiktionary.org/w/api.php?format=json&action=query&titles=res&rvprop=content&prop=revisions&redirects=1&callback=?
1条答案
按热度按时间b91juud31#