作者:手机用户2502914751 | 来源:互联网 | 2023-01-26 16:19
系统配置:macOS Sierra 10.12.5; 铬60;
我试图将JSON数据(响应对象)作为json文件下载,但是当我尝试使用浏览器File()对象实现此目的时,它会出错
Failed to construct 'File': Iterator getter is not callable.
下面是我的代码
//`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);
它然后它没有给出错误并在控制台中显示正确的对象.
1> Pavlo..:
在你的情况下,File
构造函数签名不正确,第一个参数必须是:
ArrayBuffer,ArrayBufferView,Blob或DOMString对象的Array - 或任何此类对象的混合.这是编码为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"});
看起来同样适用于`new Blob(...)`.谢谢你的明确例子.