[英]Reading data from JSON reply with JQuery
I've been having trouble accessing this piece of content in a json object.我在 json 对象中访问这段内容时遇到问题。 Here is my code for fetching data:这是我获取数据的代码:
function getEntries(key){
$.ajax({
url: "https://openlibrary.org/api/books?bibkeys=ISBN:" + key + "&jscmd=details&callback=mycallback",
dataType: "jsonp",
success: function(data){
console.log(data);
}
});
}
The reply I get looks like this:我得到的回复是这样的:
How do I access the pointed object if the key is different for every search?如果每次搜索的键都不同,我如何访问指向的对象?
Try using尝试使用
data["ISBN:"+key]
Where key is the key you are passing to the function其中 key 是您传递给函数的键
I think I found it after all...我想我终于找到了......
function getEntries(key){
$.ajax({
url: "https://openlibrary.org/api/books?bibkeys=ISBN:" + key + "&jscmd=details&callback=mycallback",
dataType: "jsonp",
success: function(data){
console.log(data["ISBN:"+key]);
}
});
}
did the trick.成功了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.