gpt4 book ai didi

javascript - 无法构造 'File' : Iterator getter is not callable in chrome 60 when use JSON. stringify()

转载 作者:行者123 更新时间:2023-12-02 23:00:52 25 4
gpt4 key购买 nike

系统配置:macOS Sierra 10.12.5; Chrome 60;

我正在尝试将 JSON 数据(响应对象)下载为 json 文件,但是当我尝试使用浏览器 File() 对象来实现此目的时,它给出了错误

无法构造"file":迭代器 getter 不可调用。

下面是我的代码

//`inputData` is the valid response getting from $http.get
var stringifyData = JSON.stringify(inputData);
console.log("stringifyData ", stringifyData);
var file = new File(blob, "filename.json", {type: "text/json;charset=utf-8"});
console.log("file", file);

问题是什么以及为什么我会收到此错误。当我使用 JSON.stringify(inputData, undefined, 4); 时,它不会给出错误并在控制台中显示正确的对象。

最佳答案

在您的情况下 File 构造函数签名不正确,第一个参数必须是:

An Array of ArrayBuffer, ArrayBufferView, Blob, or DOMString objects — or a mix of any such objects. This is the file content encoded as UTF-8.

https://developer.mozilla.org/en-US/docs/Web/API/File/File#Parameters

new File([blob], "filename.json", {type: "text/json;charset=utf-8"});

关于javascript - 无法构造 'File' : Iterator getter is not callable in chrome 60 when use JSON. stringify(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45512546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com