邮递员:发送嵌套的 JSON 对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26705782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 17:36:36  来源:igfitidea点击:

Postman: sending nested JSON object

jsongoogle-chromeasp.net-web-apipostman

提问by user3965303

I am using ASP.NET Web API: http://xyzdomain.com:16845/api/returns/returns

我正在使用 ASP.NET Web API:http: //xyzdomain.com: 16845/api/ returns/returns

How do I send a POST request to the endpoint using Postman Chrome extension, given Itemsis a collection:

如何使用 Postman Chrome 扩展程序向端点发送 POST 请求,给出Items一个集合:

[
  {
    "Items": [
      {
        "sku": "9257",
        "Price": "100",
        "Quantity": "500",
        "DiscountPercent": "1",
        "backordered": "2"
      }
    ],
    "order_id": "F429768865001",
    "status_code": "Shelf",
    "Exception": "no error"
  }
]

回答by standup75

Send it as raw data and set the type to application/json

将其作为原始数据发送并将类型设置为 application/json

enter image description here

在此处输入图片说明

回答by Peyotle

To post a nested object with the key-value interface you can use a similar method to sending arrays. Pass an object key in square brackets after the object index.

要使用键值接口发布嵌套对象,您可以使用类似于发送数组的方法。在对象索引后传递方括号中的对象键。

Passing a nested item with Postman

使用 Postman 传递嵌套项目

"Items": [
      {
        "sku": "9257",
        "Price": "100"
      }
 ]

回答by ImranNaqvi

I got it working using the Raw data option in postman, as you can see in the screen shot

enter image description here

我在邮递员中使用原始数据选项让它工作,正如你在屏幕截图中看到的

在此处输入图片说明

回答by aefhm

The key-value pair can take advanced inputs.

键值对可以采用高级输入。

Ex.

前任。

enter image description here

在此处输入图片说明

回答by TBirkulosis

This is a combination of the above, because I had to read several posts to understand.

这是上面的组合,因为我必须阅读几篇文章才能理解。

  1. In the Headers, add the following key-values:
    1. Content-Typeto application/json
    2. and Acceptto application/json
  1. Headers 中,添加以下键值:
    1. Content-Typeapplication/json
    2. Acceptapplication/json

enter image description here

在此处输入图片说明

  1. In the Body:
    1. change the type to "raw"
    2. confirm "JSON (application/json)" is the text type
    3. put the nested property there: { "Obj1" : { "key1" : "val1" } }
  1. 身体
    1. 将类型更改为“原始”
    2. 确认“JSON (application/json)”是文本类型
    3. 将嵌套属性放在那里: { "Obj1" : { "key1" : "val1" } }

enter image description here

在此处输入图片说明

Hope this helps!

希望这可以帮助!

回答by Ema.H

Simply add these parameters : In the headeroption of the request, add Content-Type:application/json

只需添加这些参数:在请求的header选项中,添加Content-Type:application/json

header content-type postman json

标题内容类型邮递员 json

and in the body, select Rawformat and put your json params like {'guid':'61791957-81A3-4264-8F32-49BCFB4544D8'}

并在正文中,选择原始格式并将您的 json 参数设置为{'guid':'61791957-81A3-4264-8F32-49BCFB4544D8'}

json request postman

json 请求邮递员

I've found the solution on http://www.iminfo.in/post/post-json-postman-rest-client-chrome

我在http://www.iminfo.in/post/post-json-postman-rest-client-chrome上找到了解决方案

回答by bhanushrestha

Just wanted to add one more problem that some people might find on top of all the other answers. Sending JSON object using RAW data and setting the type to application/jsonis what is to be done as has been mentioned above.

只是想再添加一个问题,有些人可能会在所有其他答案之上找到这些问题。使用 RAW 数据发送 JSON 对象并将类型设置application/json为如上所述。

Even though I had done so, I got error in the POSTMAN request, it was because I accidentally forgot to create a default constructor for both child class.

即使我这样做了,我还是在 POSTMAN 请求中出错,这是因为我不小心忘记为两个子类创建默认构造函数。

Say if I had to send a JSON of format:

假设我必须发送格式的 JSON:

{
 "firstname" : "John",
 "lastname" : "Doe",
 "book":{
   "name":"Some Book",
   "price":12.2
  }
}

Then just make sure you create a default constructor for Book class.

然后只需确保为 Book 类创建一个默认构造函数。

I know this is a simple and uncommon error, but did certainly help me.

我知道这是一个简单且不常见的错误,但确实对我有帮助。

回答by Suraj Kshirsagar

Select the bodytab and select application/jsonin the Content-Type drop-down and add a body like this:

选择body选项卡并在 Content-Type 下拉列表中选择application/json并添加如下所示的正文:

{
  "Username":"ABC",
  "Password":"ABC"
}

enter image description here

在此处输入图片说明

回答by techyaura

Best way to do that:

最好的方法是:

  1. In the Headers, add the following key-values:

    Content-Type to applications/json
    Accept to applications/json
    
  2. Under body, click rawand dropdown type to application/json

  1. 在标题中,添加以下键值:

    Content-Type to applications/json
    Accept to applications/json
    
  2. 在正文下,单击raw并下拉类型以application/json

Also PFA for the same

同样的 PFA

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

回答by Arpan

For a nested Json(example below), you can form a query using postman as shown below.

对于嵌套的 Json(下面的示例),您可以使用 postman 形成查询,如下所示。

{
    "Items": {
        "sku": "10 Units",
        "Price": "20 Rs"
    },
    "Characteristics": {
        "color": "blue",
        "weight": "2 lb"
    }
}

enter image description here

在此处输入图片说明