0

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)
{
}

1 Answer 1

1

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)
{}
Sign up to request clarification or add additional context in comments.

2 Comments

Hi ,I have one doubt .How to call the Post method along with the JSON object...For eg:localhost/api/Post/1/2. is not hitting the Post controller?
@user1400915: you should ask another question :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.