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)