我正在尝试使用Edmunds API数据但是当我使用示例代码时,JSON不会显示(它只是一个空白页面)。我是API的新手,只是想让JSON显示出来,所以我可以开始解析它。我做错了什么?
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Edmunds API Example</title>
</head>
<body>
<div id="results-body"></div>
<script>
window.sdkAsyncInit = function() {
// Instantiate the SDK
var res = new EDMUNDSAPI('YOUR API KEY');
// Optional parameters
var options = {
"zipcode": "90019"
};
// Callback function to be called when the API response is returned
function success(res) {
var body = document.getElementById('results-body');
body.innerHTML = "This repairshop's name is : " + res.repairshops[0].name;
}
// Oops, Houston we have a problem!
function fail(data) {
console.log(data);
}
// Fire the API call
res.api('/api/dealer/v2/repairshops', options, success, fail);
// Additional initialization code such as adding Event Listeners goes here
};
// Load the SDK asynchronously
(function(d, s, id){
var js, sdkjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "path/to/sdk/file";
sdkjs.parentNode.insertBefore(js, sdkjs);
}(document, 'script', 'edmunds-jssdk'));
</script>
</body>
</html>
答案 0 :(得分:0)
您使用的api端点必须以/
结尾(您缺少斜线)
res.api('/api/dealer/v2/repairshops/', options, success, fail);
他们的文档显示了您的代码,但他们的API控制台显示了真实的端点(http://edmunds.mashery.com/io-docs)