WEBAPI when submitting JSON with post, get no value or do not go to the corresponding method problem

Source: Internet
Author: User

Another night, and finally figured it out.

The Webapi pit was so miserable.

Before using various methods of post, sometimes can read the structure, but no value, sometimes directly is a null, and sometimes even the method is not in the run, just to the controller to see a bit ...

The last friend said or use JSON, so went back to see, finally experiment for a long time, finally succeeded.

First, the use of

: Apicontroller

interface, rather than the normal Mvccontroller

Second, the name of the method is this:

[HttpPost] public response<string> posttest ([frombody]jobject value)

Finally, get the data:

Jtoken JTK = value. GetValue ("Data"); list<model> list = jtk. Toobject<list<model>> ();

So you can get a list<model>.

Of course, to reference a DLL:

Using Newtonsoft.Json.Linq;

At the same time, the client has to do some setup:

Such as:

When sending JSON, add:

"Content-type", "Application/json"

Indicates that it is a JSON

Also, be aware of the relationship between the key and the content of data:

Data corresponding to the content is not double quotation marks.

It should be almost the same.

Well, you can have breakfast.

WEBAPI when submitting JSON with post, get no value or do not go to the corresponding method problem

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.