json - 如何从 angular6/7 中的帖子中获取大 json
问题描述
我已经迁移了一段代码,以便能够以角度将数据导出为 excel 文件。我假设 json 格式正确并从服务器发送到角度端。我可以在浏览器的网络框架中看到它。对于小json,没关系,但是当json的大小开始变大时,答案仍然失败。以下代码对应于服务调用
exportSynthesis(recordId: number, moduleId: number) {
const body = null;
return this.http.post(this.apiUrl + `/data`
+ `${recordId}/module/${moduleId}`, body,
{
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
observe: 'response', responseType: 'json' }).pipe(
map((resp: any) => {
return resp.body;
}));
}
在这里,它是管理退货的方法。
exportSynthesis() {
this.service.exportSynthesis(this.recordId, this.moduleId)
.subscribe(
(exportResult) => { this.exportResult = exportResult; },
err => {
console.log('err:', err);
this.errorHandlerService.handleError('failed', err);
},
() => {
console.log('json:', this.exportResult);
const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(this.exportResult);
const workbook: XLSX.WorkBook = { Sheets: { 'data': worksheet }, SheetNames: ['data'] };
const excelBuffer: any = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
const blob = new Blob([excelBuffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = '(GEO) ' + this.record.label + ' - name.xlsx';
a.click();
window.URL.revokeObjectURL(url);
a.remove();
});
}
目前,我不明白为什么它仍然错误地完成,我在控制台日志中只得到“ok”。任何想法?
问候
解决方案
find:
只需要使用文本作为json
return this.http.post(this.apiUrl + `/geo/v1/synthesis/xls/record/`
+ `${recordId}/module/${moduleId}`, body,
{
headers: headers,
observe: 'response',
responseType: 'text' as 'json'}).
map((resp: any) => {
return resp.body;
});
}
推荐阅读
- connection - 用户 XXX (GAM32) 的 Genexus 存储库连接失败
- opengl - 将新数据添加到缓冲区,同时将现有数据保留在 OpenGL 中
- aws-api-gateway - AWS API 网关引发 CORS 错误
- objective-c - Ubuntu下编译Objective-C
- git - git reset --hard HEAD 后恢复初始文件~
- python - 无法从 txt 文件中读取 python
- mongodb - 更改配置文件后是否需要重新启动 Mongo?
- ffmpeg - H.264 到 DNxHR 444 问题。颜色未正确转码(HDR 项目)。注:问题尚未解决
- random - 遗传算法中染色体缺失属性
- javascript - 如何返回嵌套数组中的唯一项