鏈接
https://item.taobao.com/item.htm?id=602127257823&ali_refid=a3_430673_1006:1106128557:N:emtiAWsF8%2Bzhhxaiwzc0Aw%3D%3D:381f1a75e1721adb3df1ab1c2c1e805f&ali_trackid=1_381f1a75e1721adb3df1ab1c2c1e805f&spm=a2e0b.20350158.31919782.8
url 鏈接后參數轉成 鍵值對的集合
/// <summary> /// 獲取url中的查詢字符串參數 /// </summary> /// <param name="url">鏈接</param> /// <returns>返回鏈接后參數鍵值對集合</returns> public static Dictionary<string, string> DictParameterUrl(string url) { int startIndex = url.IndexOf("?"); Dictionary<string, string> dict = new Dictionary<string, string>(); if (startIndex <= 0) return dict; string[] keyValues = url.Substring(startIndex + 1).Split('&'); foreach (string s in keyValues) { string[] pair = s.Split('='); string name = pair[0]; string value = string.Empty; if (pair.Length > 1) value = pair[1]; dict.Add(name, value); } return dict; }
獲取字典中參數
Dictionary<string, string> dict = DictParameterUrl(url);
//判斷要獲取的參數是否存在於 字典類型數據中 if (dict.ContainsKey("id")) { num_iid = dict["id"];//獲取 }