How to retrieve json parameters from postman in webapi?

If we send parameters in text format we can make use of the following code and convert it into a class object.


In your method copy the following code,

                  1.var json = await Request.Content.ReadAsStringAsync();
         
            2.clsFeilds objJson = JsonConvert.DeserializeObject<clsFeilds>(json);

In the above code stmt 1 retrieves the JSON parameters in JSON string format.

In stmt 2 when we pass the JSON string it deserializes it to a class object.


Note: To use the above code we need to make our method as ''ASYNC".

ex:
        [HttpGet]

        public async Task<string> multiple()
        {

            //        { "UserId":["12345","125545","456456","789456"]
            //} ---Sample

             var json=await Request.Content.ReadAsStringAsync();

             classname objectname=JsonConvert.DeserializeObject<classname>(json);

         }


If we send parameters in JSON format we can make use of the following code and convert it into a class object. 

Json Parameters:{"WeekEndingDates":["2019-09-08","2019-08-15"],"SupervisorID":["14202","22429"]}

ex:

          [HttpGet]
        public Task<string> WorkOrderUpdate(clsFeilds json)
        {
            //Here we can directly get the JSON parameters as class fields 
        }


In clsFeilds class,

if we want to get multiple parameters declare the field as an array type

ex: public class clsFeilds{
         public string[] SupervisorID { get; set; }


        public string[] WeekEndingDates { get; set; }
       }

Popular posts from this blog

Implement virtualisation in kendo drop down list using jquery ajax in mvc, aspx page

How to Create trigger to Update the NoofOrgs Count under each category in Category Table based on Temp Table in Sql Server

How to Preview the image and download which is in base64string format in mvc view using C#