sending nested json object using postman

2019-01-30 00:56发布

问题:

I am using Asp.net Web Api http://xyzdomain.com:16845/api/returns/returns

And i have data like below,

how do i post the end point using postman chrome extension,

Given "Items" is a collection

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

回答1:

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



回答2:

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.

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


回答3:

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



回答4:

The key-value pair can take advanced inputs.

Ex.



回答5:

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

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

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



回答6:

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-Type to application/json
    2. and Accept to application/json

Postman Headers Image

  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" } }

Postman Body Image

Hope this helps!



回答7:

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/json is what is to be done as has been mentioned above.

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.

Say if I had to send a JSON of format:

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

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

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



回答8:

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

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



回答9:

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 raw and dropdown type to application/json

Also PFA for the same



回答10:

In the Params I have added model.Email and model.Password, work for me well. Thanks for the question. I tried the same thing in headers did not work. But it worked on Body with form-data and x-www-form-urlencoded.

Postman version 6.4.4