- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我得到一个 JSON 响应,如下所示:
{
"batchcomplete": "",
"query": {
"pages": {
"97646": {
"pageid": 97646,
"ns": 0,
"title": "Die Hard",
"extract": "Die Hard is a 1988 American action film directed by John McTiernan and written by Steven E. de Souza and Jeb Stuart. It follows off-duty New York City Police Department officer John McClane (Bruce Willis) as he takes on a group of highly organized criminals led by Hans Gruber (Alan Rickman), who perform a heist in a Los Angeles skyscraper under the guise of a terrorist attack using hostages, including McClane's wife Holly (Bonnie Bedelia), to keep the police at bay.\nIt is based on Roderick Thorp's 1979 novel Nothing Lasts Forever, the sequel to 1966's The Detective, which was adapted into a 1968 film of the same name that starred Frank Sinatra. Fox was therefore contractually obligated to offer Sinatra the lead role in Die Hard, but he turned it down. The studio then pitched the film to Arnold Schwarzenegger as a sequel to his 1985 action film Commando; he turned it down, as well, and the studio finally and reluctantly gave it to Willis, then known primarily as a comedic television actor.\nMade for $28 million, Die Hard grossed over $140 million theatrically worldwide, and was given a positive reception from critics. The film turned Willis into an action star, became a metonym for an action film in which a lone hero fights overwhelming odds, and has been named one of the best action movies ever made. The film also ranks #29 on Empire magazine's 2008 list of the 500 greatest movies of all time. The film's success spawned the Die Hard franchise, which includes four sequels (Die Hard 2, Die Hard with a Vengeance, Live Free or Die Hard and A Good Day to Die Hard), video games, and a comic book."
}
}
}
}
我只想获取页面的摘录。问题是在收到响应之前我不知道 pageid,因此无法调用提取。
要获取此示例的摘录,我必须执行以下操作:
var data = JSON.parse(this.response);
console.log(suggestionData.query.pages.97646.extract);
因此,我尝试通过将页面 id 设为变量来添加到查询中来获取页面 id 的值,如下所示:
var data = JSON.parse(this.response);
var pageid = [suggestionData.query.pages[0];
console.log(suggestionData.query.pages. + pageid +.extract);
但这并没有成功,因为变量 pageid 出现为:
"97646": {
"pageid": 97646,
"ns": 0,
"title": "Die Hard",
"extract": "Die Hard is a 1988 American action film directed by John McTiernan and written by Steven E. de Souza and Jeb Stuart. It follows off-duty New York City Police Department officer John McClane (Bruce Willis) as he takes on a group of highly organized criminals led by Hans Gruber (Alan Rickman), who perform a heist in a Los Angeles skyscraper under the guise of a terrorist attack using hostages, including McClane's wife Holly (Bonnie Bedelia), to keep the police at bay.\nIt is based on Roderick Thorp's 1979 novel Nothing Lasts Forever, the sequel to 1966's The Detective, which was adapted into a 1968 film of the same name that starred Frank Sinatra. Fox was therefore contractually obligated to offer Sinatra the lead role in Die Hard, but he turned it down. The studio then pitched the film to Arnold Schwarzenegger as a sequel to his 1985 action film Commando; he turned it down, as well, and the studio finally and reluctantly gave it to Willis, then known primarily as a comedic television actor.\nMade for $28 million, Die Hard grossed over $140 million theatrically worldwide, and was given a positive reception from critics. The film turned Willis into an action star, became a metonym for an action film in which a lone hero fights overwhelming odds, and has been named one of the best action movies ever made. The film also ranks #29 on Empire magazine's 2008 list of the 500 greatest movies of all time. The film's success spawned the Die Hard franchise, which includes four sequels (Die Hard 2, Die Hard with a Vengeance, Live Free or Die Hard and A Good Day to Die Hard), video games, and a comic book."
}
我也想使用 javascript 而不是 jQuery 等。
最佳答案
试试这个 fiddle :https://jsfiddle.net/u9dnm70b/
var response = '{"batchcomplete": "","query": {"pages": {"97646": {"extract": "abcd" }}}}';
var suggestionData = JSON.parse(response);
var pageid = Object.keys(suggestionData.query.pages)[0];
console.log(suggestionData.query.pages[pageid].extract);
关于javascript - 从 Wikipedia API 检索摘录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41428334/
我使用 wikipedia api 取得了一些成功,但我需要一些帮助来捕获返回的数据,并将其显示到页面上。我的代码笔的链接是 https://codepen.io/rynsp8/pen/jYyYog
我目前建立了一个系统,我可以从旧帖子/类别中进行训练,并尝试预测新帖子将属于哪个类别。我使用带有 TfidfVectorizer 和 LinearSVC 的管道来训练数据集并将其存储在 pickle
布局是这样的: 感兴趣的是窗口的上半部分;它是一个充满标签的 GridPane,我添加了填充,但是...... 嗯,问题很明显:
(let ((g (* 2 (or (gethash word good) 0))) (b (or (gethash word bad) 0))) (unless (/ngood(作
这个问题在这里已经有了答案: Why is i++ not atomic? (10 个答案) 关闭 7 年前。 如果按照 Effective Java 的摘录下面,类型为 int(整数)的变量在 J
Wordpress 的文档建议将以下内容添加到functions.php 中以实现我想要执行的操作: function new_excerpt_more($post) { return 'ID
我添加了此 PHP 函数以在存档页面上显示我的产品摘录,但它会影响我的其余样式。 我试图阻止我的摘录中的 CSS 影响页面的其余部分。基本上我只想要没有自己的样式或元素符号或图像等的文本。 这是添加的
我正在创建一个 WordPress 模板,现在需要一些代码来创建一个循环来显示所有帖子,但不显示完整帖子,仅显示摘录。 有人可以帮忙吗? 最佳答案 使用此代码生成循环中的摘录: 以上内容仅生成帖子的
我刚刚将我的 Hexo 博客更新到最新版本。更新后,标签似乎停止工作。它没有在主页上显示摘录,而是显示所有内容。我正在使用 Next 主题。 我在hexo github上发现了一个问题:https:/
我正在运行 WordPress REST API(在 WordPress 4.7.3 上),当我点击/wp-json/wp/v2/posts 时,我正在为我的帖子取回 JSON,但内容和摘录字段显示为
我正在编写一些 php 来查询我的 wordpress 博客数据库并在 wordpress 环境之外的主页上显示最新帖子。 我不是很精通 php,但我已经能够显示最新的博客标题以及帖子内容。我想做的是
我目前正在使用 WordPress 和 Yoast WordPress SEO 插件开发我们的网站。我已经检查了 HTML 源并且存在 OpenGraph 元信息: 我们网站 www.verstric
我是一名优秀的程序员,十分优秀!