Capture 100 of Express data for express query

Source: Internet
Author: User

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

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.