【发布时间】:2020-10-31 07:33:39
【问题描述】:
我在 Angular 8 中进行 API POST 调用。我必须在调用中发送一个 JSON 对象,该对象应该是结构:
-{}JSON
-{}data
-[]exp
+{} 0
+{} 1
但我以这种格式发送数据:
-[]JSON
+{} 0
+{} 1
在我的打字稿中,我在名为 receivedData 的数组中获得了两个对象 {}0, {}1,然后我将数据存储为:
this.changedData = this.receivedData;
this.postService.postMethod(this.headers, this.changedData)
在我的帖子服务中:
postMethod(header, changedData): Observable<any[]> {
return this.http.post<any>(`the url here`, changedData, {headers: header, responseType: 'text' as 'json'})
.pipe(map(response => {
return response;
}))
}
如何以上述格式发送数据?我希望 changedDetails 的 json 结构与顶部提到的相同,具有相同的命名约定,例如:{}data and []exp 如何将receivedData objects 推送到 exp[] 然后我可以将其发送到 data{} 然后将是完全推入changedDetails {}
【问题讨论】:
标签: json angular typescript api angular8