【发布时间】:2019-10-08 10:17:36
【问题描述】:
我对这一切还比较陌生,但我正在尝试访问 Wikipedia 的 API 以检索“extract”的值并将文本附加到 html 元素。问题是“页面”会根据用户输入而改变。有没有办法访问给定 JSON 响应中的随机数的信息? *编辑-我正在使用 Jquery/Javascript。 这是我发送的 API 请求: https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&titles=Pug
{
"batchcomplete": "",
"query": {
"normalized": [
{
"from": "pug",
"to": "Pug"
}
],
"pages": {
"21234727 (this number is will change/be random)": {
"pageid": 21234727,
"ns": 0,
"title": "Pug",
"extract": "The pug is a breed of dog with physically distinctive features of a wrinkly, short-muzzled face, and curled tail. The breed has a fine, glossy coat that comes in a variety of colours, most often fawn or black, and a compact square body with well-developed muscles.\nPugs were brought from China to Europe in the sixteenth century and were popularized in Western Europe by the House of Orange of the Netherlands, and the House of Stuart. In the United Kingdom, in the nineteenth century, Queen Victoria developed a passion for pugs which she passed on to other members of the Royal family.\nPugs are known for being sociable and gentle companion dogs. The American Kennel Club describes the breed's personality as \"even-tempered and charming\". Pugs remain popular into the twenty-first century, with some famous celebrity owners. A pug was judged Best in Show at the World Dog Show in 2004."
}
}
}
}
【问题讨论】:
-
你用什么语言来解析 json?
-
抱歉,感谢您的回复。我正在使用 JQuery/Javascript。
-
您好,我更新了答案以包含 Javascript 版本。
标签: javascript jquery json parsing wikipedia-api