[英]How to send an array as a JSON string in postman body?
I'm trying to send some body data in my api call using postman. (I'm using the "raw" body option)我正在尝试使用 postman 在我的 api 呼叫中发送一些身体数据。(我正在使用“原始”身体选项)
My data in the body is like so:我体内的数据是这样的:
{
"products" : [{"id": 1, "quantity" : 2, "comments": "none"}]
}
Problem is, when I send the json body data containing an array, i get an error saying问题是,当我发送包含数组的 json 正文数据时,我收到一条错误消息
The Products must be a valid JSON string
I have set my headers to content-type: application/json, but nothing is working, am I missing something?我已将标头设置为内容类型:application/json,但没有任何效果,我是不是遗漏了什么?
Your JSON is valid.您的 JSON 有效。
This should work for you:这应该适合你:
var request = {
method: "POST",
url: "http://example.com/api",
headers: {
"Content-Type": "application/json; charset=utf-8"
},
body: "{\"products\":[{\"id\":1,\"quantity\":1,\"comments\":\"none\"},{\"id\":2,\"quantity\":3,\"comments\":\"Super good product\"},{\"id\":3,\"quantity\":6,\"comments\":\"not so good product\"}]}"
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.