-->

Simple JSON Response With HTTP Status C# – Web API

03 2020

Here is a simple Snippet for JSON Response with HTTP Status Code for WEB API in C#.

Case 1 :

public class SampleController : ApiController
{
    public IHttpActionResult Post([FromBody] string value)
    {
       return Ok(new {  IntVal = 1  ,  StrVal = "TWO" } );  
    }
}

Case 2 :

public class SampleController : ApiController
{
    public IHttpActionResult Post([FromBody] string value)
    {
        int Obj1_Value = 10;
        List JSON_Return;
        JSONReturn = new List { "Object1", Obj1_Value.ToString() };
        return Ok>(JSON_Return);  
    }
}

Leave a Reply