【发布时间】:2019-12-05 13:39:39
【问题描述】:
在我当前的 Angular 8 项目中,我必须连接两个 JSON 文件。连接后,新文件应上传到服务器。 这些文件是通过两个 HTML 输入标签选择的。
<input id="file_1" name="file_1" type="file">
<input id="file_2" name="file_2" type="file">
<button buttonLabel="convert" (click)="postJson()"></button>
JSON 1 的开始:
{
"result": 0,
"deviceInfos": [{
"deviceIndex": 1,
"info": {
"name": "Test1234",
"type": "Test",
"serialNumber": 123456,
"canBus": 0,
"canPos": 1,
.....
JSON 2 的开始:
{
"result": 0,
"deviceDescriptions": [
{
"deviceIndex": 1,
"deviceTypeId": 34567,
"descriptions": [{
"name": "Temp.Test",
"unitName": "",
"dataType": "string",
"constraints": {
"maxLen": 40,
"regExpr": "^([-_ a-zA-Z0-9]{0,40})$"
},
......
我的实际组件:
export class JsonConverterComponent implements OnInit {
constructor(private http: HttpClient) { }
ngOnInit() {
}
postJson() {
this.http.post(url, jarray)
.subscribe(res =>
console.log(res.json(
))
);
}
}
我不知道如何在单击按钮后访问这两个文件然后合并它们。
我该怎么做?
【问题讨论】:
-
你试过解决方案了吗?
-
是的,它工作正常。谢谢
标签: arrays json angular angular8