简体   繁体   English

如何在 postman 主体中将数组作为 JSON 字符串发送?

[英]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.

相关问题 如何发送 JSON object 作为 JSON 字符串与 Postman? - How to send JSON object as JSON String with Postman? 测试Postman响应体Json是数组还是对象 - Test if Postman response body Json is an array or object Postman 条件测试 json 主体数组是否为空 = 跳过测试 - Postman conditional tests if json body array is empty = skip tests 如何发送带有json正文的帖子请求,其中正文仅包含一个字符串而不是键值对? - How do I send post request with json body where the body only contains a string not a key value pair? Hapijs:如何在POSTMAN中发送POST对象数组 - Hapijs : How to send POST objects array in POSTMAN 如何在 Postman 集合中指定 JSON 请求正文示例 - How to specify JSON request body example in Postman Collection 在POST方法中使用Postman发送正文JSON以在MS SQL Server中执行过程 - Send body JSON with Postman in a POST method to execute procedure in ms sql server 解析 Postman 中的 JSON 数组 - Parse JSON Array in Postman 如何以邮递员形式数据发送对象数组并作为对象数组接收 - How to send array of objects in postman form data and and receive as array of objects 如何将数组缓冲区数据与字符串/json一起发送到NodeJS服务器 - How to send array buffer data along with string/json to NodeJS server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM