【发布时间】:2020-12-03 11:14:45
【问题描述】:
希望你能帮帮我,我需要像这样发送一些json格式的参数:
{
"InformationA": {
"str_id": 1,
"str_description": "message",
"str_email": "abcd@abcd.com.co"
},
"AddConfiguration": [
{
"int_code": 1,
"str_valor": "32201"
},
{
"int_code": 104,
"str_valor": "https://www.google.com.co/"
},
{
"int_code": 108,
"str_valor": "1"
}
]
}
我正在尝试以这种方式通过角度服务发送json但我不知道它是否正确?:
sendData(InformationA,AddConfiguration){
const params = 'InformationA=' +JSON.stringify(InformationA)+'AddConfiguration=' +
JSON.stringify(AddConfiguration);
return this.http.post<any>(`${this.route}/send-data`, params , { headers: this.headers });
}
还在 nodejs 后端创建一个函数来查看它是如何到达的:
@Post('send-data')
async receibeData(@Req() req, @Res() res) {
try {
const data = req.body;
res.status(HttpStatus.OK).json(data)
} catch (err) {
throw err;
}
}
并通过控制台以这种方式打印:
{,…}
InformationA:"
[{"str_id":"1","str_description":"message","str_email":"abcd@abcd.com.co"}]Addconfiguration=
[{"int_code":1,"str_valor":"32201 "},{"int_code":104,"str_valor":"https://www.google.com.co
"},{"int_code":108,"str_valor":"1 "}]"
我对此真的很陌生,我想知道如何调整我的数据以便可以按要求发送。
【问题讨论】:
标签: node.js json angular express