0

I have an action in controller which performs a logic to return a list of json objects. In postman, I want to get this list in json format.

    [HttpPost("display")]
    [Produces("application/json")]
    public async Task<IActionResult> DisplayPersons([FromBody] Person person)
    {
           var generatedFile = JsonConvert.DeserializeObject<List<dynamic>>(await 
                      httpResponse.Content.ReadAsStringAsync());
            
            return Ok(generatedFile);
    }

When I put a breakpoint on the generatedFile, I get the values. But on postman, it does not display anything. How can I display the nested list of json objects on postman?

1 Answer 1

1

Here is a demo to pass List to postman,you need to make sure generatedFile is a list<object>,and in postman response you need to make sure status is 200 and you are watching body rather than Cookies,Headers or Test Results: enter image description here

Controller:

        [HttpPost("display")]
        [Produces("application/json")]
        public async Task<IActionResult> DisplayPersons([FromBody]List<dynamic> list)
        {
            return Ok(list);
        } 

Testjson:

[
    {
    "Id":1,
    "Name":"sss",
    "Class":"c1"
    },
    {
    "Id":2,
    "Name":"www",
    "Class":"c2"
    }
]

result: enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.