我正在使用这里的交通 API,它应该返回如下内容:{TIMESTAMP: "03/14/2021 19:40:57 GMT", VERSION: 5, TRAFFICITEMS: {…}}
它大部分时间都有效,但每隔一段时间就会返回:{TIMESTAMP: "03/14/2021 19:40:57 GMT", VERSION: 5}
第二个示例是如果没有交通事故,但进一步刷新将返回第一个示例。代码没有任何变化;我只是刷新页面。不管返回没有错误;我只是不知道为什么它有时不准确
return fetch(`https://traffic.ls.hereapi.com/traffic/6.0/incidents.json?corridor=36.18377,-86.69355;36.08026,-86.92807;36.14638,-86.80963;36.18377,-86.69355%3B20&apiKey={API Key}`)
.then(res => {
if (res.ok) {
console.log("got a good response",res)
return res
} else {
console.log("you don't want that response")
}
})
.then(res => res.json())
.then(res => console.log("response",res))