找不到“object”类型的不同支持对象“[object Object]”。 --> 要在表格中显示的 VirusTotal JSON
Posted
技术标签:
【中文标题】找不到“object”类型的不同支持对象“[object Object]”。 --> 要在表格中显示的 VirusTotal JSON【英文标题】:Cannot find a differ supporting object '[object Object]' of type 'object'. --> VirusTotal JSON to Display in a Table 【发布时间】:2020-06-22 00:59:06 【问题描述】:我正在尝试从 VirusTotal JSON 解析数据以显示在表格中。但我无法使用 ngfor
scan(file)
this.http.get("api/Scanner/").subscribe(result =>
this.value = result;
console.log(this.value.scans);
);
在 Html 文件中
<li *ngFor="let item of this.value.scans">
item.version
</li>
public class ScannerController : Controller
[HttpGet]
public async Task<IActionResult> ScanAsync(string file_id)
//New Update //
file_id = "./wwwroot/Upload/1";
VirusTotal virusTotal = new VirusTotal("mykey");
// virusTotal.UseTLS = true;
FileStream stream = System.IO.File.OpenRead(file_id);
byte[] fileBytes = new byte[stream.Length];
// stream.Seek(0, SeekOrigin.Begin);
stream.Read(fileBytes, 0, fileBytes.Length);
VirusTotalNet.Results.FileReport report = await virusTotal.GetFileReportAsync(fileBytes);
bool hasFileBeenScannedBefore = report.ResponseCode == FileReportResponseCode.Present;
Console.WriteLine("File has been scanned before: " + (hasFileBeenScannedBefore ? "Yes" : "No"));
//If the file has been scanned before, the results are embedded inside the report.
if (hasFileBeenScannedBefore)
return Ok(report);
else
ScanResult fileResult = await virusTotal.ScanFileAsync(fileBytes,"1");
return Ok(fileResult);
错误
UploadComponent.html:8 ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
更新:
Bkav: …, TotalDefense: …, MicroWorld-eScan: …, FireEye: …, CAT-QuickHeal: …, …
Bkav: detected: false, version: "1.3.0.9899", result: null, update: "20200221"
TotalDefense: detected: false, version: "37.1.62.1", result: null, update: "20200225"
MicroWorld-eScan: detected: false, version: "14.0.409.0", result: null, update: "20200226"
FireEye: detected: false, version: "29.7.0.0", result: null, update: "20200226"
CAT-QuickHeal: detected: false, version: "14.00", result: null, update: "20200225"
McAfee: detected: false, version: "6.0.6.653", result: null, update: "20200226"
Malwarebytes: detected: false, version: "3.6.4.335", result: null, update: "20200225"
Zillya: detected: false, version: "2.0.0.4034", result: null, update: "20200225"
SUPERAntiSpyware: detected: false, version: "5.6.0.1032", result: null, update: "20200221"
Sangfor: detected: false, version: "1.0", result: null, update: "20200221"
K7AntiVirus: detected: false, version: "11.96.33381", result: null, update: "20200226"
K7GW: detected: false, version: "11.96.33380", result: null, update: "20200226"
BitDefenderTheta: detected: false, version: "7.2.37796.0", result: null, update: "20200211"
F-Prot: detected: false, version: "4.7.1.166", result: null, update: "20200226"
Symantec: detected: false, version: "1.11.0.0", result: null, update: "20200226"
ESET-NOD32: detected: false, version: "20902", result: null, update: "20200226"
Baidu: detected: false, version: "1.0.0.2", result: null, update: "20190318"
TrendMicro-HouseCall: detected: false, version: "10.0.0.1040", result: null, update: "20200226"
Avast: detected: false, version: "18.4.3895.0", result: null, update: "20200226"
ClamAV: detected: false, version: "0.102.2.0", result: null, update: "20200225"
Kaspersky: detected: false, version: "15.0.1.13", result: null, update: "20200226"
BitDefender: detected: false, version: "7.2", result: null, update: "20200226"
更新:
【问题讨论】:
你也应该分享你的角度代码 @BunyaminCoskuner 请查看更新。console.log(this.value.scans);
行向控制台写入了什么?它是可迭代的吗?
@BunyaminCoskuner 请查看更新。
【参考方案1】:
this.value.scans
不是一个数组,而是一个对象。让我们把它转换成一个数组。
this.http.get("api/Scanner/").subscribe(result =>
this.value = result;
// this line will transform your object to an array
this.value.scans = Object.keys(this.value.scans).map(key =>
return
...this.value.scans[key],
scannerName: key
;
);
);
【讨论】:
@techno 我已经更新了我的答案。现在每个对象也有scannerName
以上是关于找不到“object”类型的不同支持对象“[object Object]”。 --> 要在表格中显示的 VirusTotal JSON的主要内容,如果未能解决你的问题,请参考以下文章
错误:找不到类型为“object - Angular 7”的不同支持对象“[object Object]”[重复]
找不到“object”类型的不同支持对象“[object Object]”。 NgFor 仅支持绑定到 Iterables,例如 Arrays.(AngularFireList)
找不到“object”类型的不同支持对象“[object Object]”。 NgFor 仅支持绑定到 Iterables,例如带有异步管道的数组
Angular 4 找不到“object”类型的不同支持对象“[object Object]”。 NgFor 仅支持绑定到 Iterables,例如 Arrays
找不到“object”类型的不同支持对象“[object Object]”。仅支持在从 JSON 文件读取和解析数据时绑定到 Iterables
找不到“object”类型的不同支持对象“[object Object]”。 --> 要在表格中显示的 VirusTotal JSON