我希望从Goodreads API检索某本书的评论。我是API方面的新手。
这里有一个指向API文档的链接:https://www.goodreads.com/api#book.show
我已经创建了这段基本代码,它输出成功,但没有结果。数据:对象文档。下面是我的代码:
$.get("https://www.goodreads.com/book/isbn?format=xml&key=d9xonLKxHDCI5HF1mHjbQ&isbn=9781843589501", function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});为了能够显示结果,我遗漏了什么?接入点
发布于 2016-02-12 03:25:21
返回的结果为XML格式。您需要在客户端设置一些内容来读取检索到的XML。看一下下面的示例https://api.jquery.com/jQuery.parseXML/
发布于 2018-03-04 10:42:37
我使用了一个名为:xml2js的外部库
下面是一段代码片段,它使返回值像对象一样。
var parseString = require("xml2js").parseString;
request(options)
.then(function(data) {
var xml = data;
parseString(xml, { trim: true }, (err, result) => {
if (err) //do something
else //something else因此,在这里,您可以获取数据,将其转换为JSON,然后可以根据需要对其执行相应的操作。不过,要意识到这里有一个回调!
https://stackoverflow.com/questions/35348150
复制相似问题