WEBAPI biography (Fri)

Source: Internet
Author: User

On the last mention of multiple entities involved in the transfer of parameters, using the conventional method has not been solved. This time we're going to use the ultimate trick to fix her.

WebApi: Note to refer to Json.NET

[HttpPost] Public stringGetData (stringName,jobject obj) {            DynamicJSON = obj;//Get dynamic ObjectsJobject Womanjson = Json.woman;//Getting a child object in a dynamic objectJobject Sonjson =Json.son; varWoman = womanjson.toobject<woman> ();//convert it to a strongly typed object            varson = Sonjson.toobject<son> ();//convert it to a strongly typed object            return "I was"+ name +", I like"+ Woman. name+"we have a common child called:"+son. name+"the first time of daily breastfeeding:"+son. eattime[0]; }
View Code

Client:

        Private voidBtnpost_click (Objectsender, EventArgs e) {            varWoman =New{Name="Liu Yifei", Age= -, Exercisetime=NewList<datetime>() {DateTime.Now.Date.AddHours ( -), DateTime.Now.Date.AddHours ( -)}, Son=New Object[]{New{//because of the anonymous class, the list cannot be used here, only the object arrayName ="Aubagne 555", Age=1, Eattime=NewList<datetime> () {//This is a strong type, so you can standardize the dataDateTime.Now.Date.AddHours (9), DateTime.Now.Date.AddHours ( +)                    }                }},            }; varson =New{Name="Lou Feizi", Age=1, Eattime=NewList<datetime> () {//This is a strong type, so you can standardize the dataDateTime.Now.Date.AddHours (7), DateTime.Now.Date.AddHours ( +)                    }            }; stringPostData = Jsonconvert.serializeobject (New{woman=woman,son=son}); stringURL ="http://localhost:7601/api/values/GetData?name= landlord"; Postservice.asyncpostapirequest (URL, postdata, -); }
View Code

Run result 1:

Run result 2:

Wood haha, yy success.

This series of articles refer to:

http://www.cnblogs.com/CreateMyself/p/4874273.html Thanks recluse_xpy

http://www.cnblogs.com/xcjit/p/4346758.html thanks to the man plume

http://www.cnblogs.com/liek/p/4888201.html Thanks for steering This life

http://www.cnblogs.com/babycool/p/3922738.html thanks to cool kids.

Http://blogs.msdn.com/b/henrikn/archive/2012/05/03/asp-net-web-api-updates-may-3.aspx

http://weblog.west-wind.com/posts/2012/Aug/30/Using-JSONNET-for-dynamic-JSON-parsing thanks to Rick Strahl. They knew it in 2012 years. Gap Ah, this man wrote a lot of articles, just don't know how high status.

WEBAPI biography (Fri)

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.