I changed my job in March to a logistics system. Sometimes I need to query external express delivery interfaces for tracking and query. Here I will take a brief introduction to 100 of express delivery data.
For more information, see.
First:
Next we will discuss how to implement this function step by step.
1. Preparation: get 100 Json data of express delivery
By our discovery of express 100 query Road strength: http://www.kuaidi100.com/query? Type = yuw.g & postid = 5714113854 & id = 1 & valicode = & temp = 0.19689508604579842
Two important parameters are type: courier company code, postid: courier ticket number
2. Design code-design
Here is a tip: copy json data.
1 public class ExpressStack <T> 2 {3 public string message {get; set;} 4 public string nu {get; set;} 5 public string ischeck {get; set ;} 6 public string com {get; set;} 7 public string status {get; set;} 8 public string condition {get; set;} 9 public string state {get; set ;} 10 public List <T> data {get; set;} 11} 12 13 public class Data14 {15 public string time {get; set;} 16 public string context {get; set;} 17 public string ftime {get; set;} 18}
In this way, we don't need to write code, and the class is designed (with deletions). We use generic classes to process Json data.
3. Write Action
This is relatively simple, some json conversion and output
Public ActionResult Search () {return View ();} [HttpPost] public ActionResult Search (string type, string postId) {WebClient wClient = new WebClient (); wClient. encoding = Encoding. UTF8; var response = wClient. downloadString ("http://www.kuaidi100.com/query? Type = "+ type +" & postid = "+ postId); var oJson = JsonConvert. DeserializeObject <ExpressStack <Data> (response); return View (oJson );}
4. View display data
Do not handle exceptions here. You can add
@ Using KuaiDi100.Controllers; @ model ExpressStack <Data>
The running effect is the same as the first figure above, and the source code is on it. For more information, see. If it helps you, click the top button in the article, thank you for your support.
Capture 100 of Express data for express query