我是角色的新手我在下面遇到的问题是我的jsonlist
{Id: 1, Name: "A", Status: false, CustTrack: false, RoleId: 1}
{Id: 2, Name: "B", Status: true, CustTrack: false, RoleId: 1}
{Id: 3, Name: "C", Status: true, CustTrack: false, RoleId: 1}
{Id: 5, Name: "D", Status: true, CustTrack: false, RoleId: 1, …}
{Id: 5, Name: "E", Status: true, CustTrack: false, RoleId: 1, …}
{Id: 6, Name: "F", Status: true, CustTrack: false, RoleId: 1, …}
{Id: 7, Name: "G", Status: true, CustTrack: false, RoleId: 1, …}
我想使用帖子请求将上述Json列表发送到服务器,下面是我的帖子请求格式
{
"LocationId": 0,
"StaffId": 0,
"CardDetails": [
{
"id": 0,
"Name": "string",
"Status": true,
"CustTrack": true,
"RoleId": 0
}
]
}
我怎样才能实现这个目标
Json格式 [{ “ID”:1, “名称”: “A”, “状态”:假 “CustTrack”:假, “角色ID”:1, “LocationId”:2 “CurrentStatus”:假},{“ID “:2,” 名称 “:” B”, “状态”:真 “CustTrack”:假, “角色ID”:1, “LocationId”:2 “CurrentStatus”:假},{ “ID”:3, “名称”: “C”, “状态”:真 “CustTrack”:假, “角色ID”:1, “LocationId”:2 “CurrentStatus”:假},]
答案 0 :(得分:0)
要发送的对象:
let array = [{
"Id": 1,
"Name": "A",
"Status": false,
"CustTrack": false,
"RoleId": 1,
"LocationId": 2,
"CurrentStatus": false
}, {
"Id": 2,
"Name": "B",
"Status": true,
"CustTrack": false,
"RoleId": 1,
"LocationId": 2,
"CurrentStatus": false
}, {
"Id": 3,
"Name": "C",
"Status": true,
"CustTrack": false,
"RoleId": 1,
"LocationId": 2,
"CurrentStatus": false
}];
let jsonToSend = {
"LocationId": 0,
"StaffId": 0,
"CardDetails": array
}
HTTP请求:
this.http.post('url', jsonToSend)
.subscribe(reponse => {
console.log('response from the server', response);
}, err => {
console.error('Error occurred while sending request', err);
});