我想把这样的数据发送到rest Web服务:
let params = {
uri: getWsUrl(),
body:queryString.stringify({
city: 885,
customer: user.id,
basket: [
[
product_id: 448025,
count: 2
]
]
})
};
我使用request.post(params, function(...))
方法将参数发送到Web服务。将此请求发送到服务器后,我使用$_POST获得参数,但basket
为空!你能帮我吗?
对于在响应中使用render发送数据,请考虑以下示例
response.end(JSON.stringify({'title': 'Welcome', 'subtitle': "Users List", 'user': result}));
您正试图将嵌套数组当作对象来发送。
你有两个选择。将数组中的数组更改为对象。
city: 885,
customer: user.id,
basket: [
{
product_id: 448025,
count: 2
} //HERE
]
}
或者,如果你真的想把数组放在那里(请不要。尽量保持你的数据尽可能平坦。
你可以这样做(不推荐(。只需将其包裹在对象中
city: 885,
customer: user.id,
basket: [
[{
product_id: 448025,
count: 2
}]
]
}