user1400915
user1400915

Reputation: 1943

Json object using WebAPI controller

I am using webapi controller.I have to pass an JSON object from Java applet to web api controller. How to write a web api controller method to accept the JSON object

public test GetPo(int id)
{
}

Upvotes: 0

Views: 802

Answers (1)

cuongle
cuongle

Reputation: 75306

ASP.NET Web API uses JSON format as default format:

JSON formatting is provided by the JsonMediaTypeFormatter class. By default, JsonMediaTypeFormatter uses the Json.NET library to perform serialization. Json.NET is a third-party open source project.

what you just do is to defined your model object which map with json:

public class Model
{
    public int Property1 { get; set; }
    public string Property2 { get; set; }

    // More properties
}

And your POST method:

public void Post(Model model)
{}

Upvotes: 1

Related Questions