从自我下载URL获取JSON数据
我制作了一些代码,以JSON格式从URL获取数据。但是,今天我遇到了一个URL,即当您使用它时,它会自动启动下载。当我下载并使用浏览器打开它时,我会在浏览器中看到JSON格式数据。因此,要读取此数据,我必须修改我的代码才能在本地读取该下载的文件。但是我不想这样做,因为我不想将数据存储在计算机上。是否可以读取此JSON数据而无需实际下载?
编辑:@Amadan ...如果我将链接粘贴到浏览器中,然后按Enter。当然,如果我在nodejs中获取链接,我会收到一个错误消息。我的获取方法非常适合链接到JSON页面的链接,这些链接在浏览器中粘贴链接时不会触发下载。
我获取以下代码:
export async function retrieveData(url)
{
return await fetch(url)
.then(response => response.json())
.then((jsonData) => {
// jsonData is parsed json object received from url
return jsonData;
})
.catch((error) => {
throw error;
});}
我收到的错误消息说:未接收(在承诺中)TypeError:未能获取
I made some code that fetches data from url's in JSON format. However, I encountered today a url that when you go to it, it automatically starts a download. When I take this download and open it with a browser, I see JSON format data in my browser. So in order to read this data I have to modify my code to locally read that downloaded file. But I don't want to do that because I don't want to store the data on my computer. Is it possible to read this JSON data without actually downloading it ?
edit: @Amadan ... The downloading start if I paste the link in the browser and press enter. Of course if I fetch the link in NodeJS I get an error message. My fetch method works perfect for links to JSON pages that don't trigger a download when I paste the link in the browser.
I fetch with following code:
export async function retrieveData(url)
{
return await fetch(url)
.then(response => response.json())
.then((jsonData) => {
// jsonData is parsed json object received from url
return jsonData;
})
.catch((error) => {
throw error;
});}
The error message I got says: Uncaught (in promise) TypeError: Failed to Fetch
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论