100快递查询
本示例是.NET获取快递100提供的查询快递信息的方法的一个案例。
效果截图:
窗体调用代码:
[C#] 纯文本查看 复制代码 public partial class kuaidi : Form
{
public kuaidi()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string fileName = "Database.xml";
DataSet xmlread = new DataSet();
xmlread.ReadXml(fileName);
cbKuaidi.DataSource = xmlread.Tables[0];
cbKuaidi.ValueMember = "key";
cbKuaidi.DisplayMember = "com";
}
private void button1_Click(object sender, EventArgs e)
{
txtResult.Text = "";
string com=cbKuaidi.SelectedValue.ToString();
string sn=txtSN.Text;
string json = HttpRequstCommand.HttpGet("http://www.kuaidi100.com/query", "type=" + com + "&postid=" + sn);
Dictionary<string,object> ht = JsonCommon.SelectDictionary(json);
if (ht["status"].ToString() == "200")
{
ArrayList aList = new ArrayList();
aList = (ArrayList)ht["data"];
for (int i = 0; i < aList.Count; i++)
{
Dictionary<string, object> di = (Dictionary<string, object>)aList[i];
txtResult.Text += "处理时间:" + di["time"] + "|" + di["context"]+"\r\n";
}
}
else
{
txtResult.Text = "快递或单号错误";
}
}
}
源码案例下载:
|