using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using AllBase; namespace Work { public class AddressSetIni { public static Dictionary> Addresses = new Dictionary>(); public static List AddressList = new List(); public void Ini() { string file = FileBase.ReadAllText("taobao_address.tjm", Encoding.UTF8); if (string.IsNullOrEmpty(file)) { MessageBox.Show("初始化淘宝地址信息错误,请检查网络", "提示"); return; } var m = BaseRegex.GetMatchRegex(ref file, @"\[""([\d]+)"",\[""([^""]+?)"",""[^""]+?""\],""([\d]+)"""); for (int i = 0; i < m.Count; i++) { AddressBase a = new AddressBase(); a.Id = int.Parse(m[i].Groups[1].Value); a.Name = m[i].Groups[2].Value; a.UpId = int.Parse(m[i].Groups[3].Value); AddressList.Add(a); if (!Addresses.ContainsKey(a.Id)) Addresses.Add(a.Id, new List()); if (!Addresses.ContainsKey(a.UpId)) Addresses.Add(a.UpId, new List()); Addresses[a.UpId].Add(a); } } #region 获取阿里巴巴省市县区的地址 public static Dictionary> Addressdic = new Dictionary>(); public static List AddressAllList = new List(); public void getAddress1688() { //Thread.Sleep(2000); string file = FileBase.ReadAllText("1688_address.tjm", Encoding.UTF8); if (string.IsNullOrEmpty(file)) { MessageBox.Show("初始化1688址信息错误,请检查网络", "提示"); return; } string strContent = FileBase.ReadAllText("1688_address.tjm"); strContent = GetHtml.UrlDecode(strContent); var m = BaseRegex.GetMatchRegex(ref strContent, @"{[^}]+?}"); for (int i = 0; m != null && i < m.Count; i++) { string addressContent = m[i].Groups[0].Value; AddressBase a = new AddressBase(); string[] addressArray = addressContent.Split(','); for (int j = 0; j < addressArray.Length; j++) { var itemMatch = BaseRegex.GetMatchRegex(ref addressArray[j], @"([\w\W]+?):([\w\W]+)"); string itemname = itemMatch[0].Groups[1].Value.Replace("{", ""); string itemvalue = itemMatch[0].Groups[2].Value.Replace("\"", "").Replace("}", ""); if (itemname == "a") { a.Id = int.Parse(itemvalue); } if (itemname == "n") { a.Name = itemvalue; } if (itemname == "p") { a.UpId = int.Parse(itemvalue); } } AddressAllList.Add(a); if (!Addressdic.ContainsKey(a.Id)) Addressdic.Add(a.Id, new List()); if (!Addressdic.ContainsKey(a.UpId)) Addressdic.Add(a.UpId, new List()); Addressdic[a.UpId].Add(a); } } #endregion } public class AddressBase { public int Id = 0; public string Name = ""; public int UpId = 0; //public Dictionary Address = new Dictionary(); } }