foreach (var l in jobject["subways"]["l"]) { var line = new Line { Name = l["l_xmlattr"]["lb"].Value<string>() }; foreach (var p in l["p"]) { var pname = p["p_xmlattr"]["lb"].Value<string>(); if (!string.IsNullOrWhiteSpace(pname) && p["p_xmlattr"]["uid"] != null) line.Stations.Add(new Station { Name = pname, Lines = p["p_xmlattr"]["lb"].Value<string>().Split(',').Select(s => s.Substring(s.IndexOf("|") + 1)).ToList(), UId = p["p_xmlattr"]["uid"].Value<string>() }); } Lines.Add(line); }
var stationsList = Lines.Select(l => l.Stations); var stations = new List<Station>(); foreach (var ss in stationsList) stations.AddRange(ss);
var client = new HttpClient();
for (var i = 0; i < stations.Count; i++) { for (var j = 0; j < stations.Count; j++) { if (i == j) continue; if (TwoStationInfos.Any(ts => ts.TwoStationNames.Contains(stations[i].Name) && ts.TwoStationNames.Contains(stations[j].Name))) continue; var result = await client.GetStringAsync( $"https://api.map.baidu.com/?qt=bt2&newmap=1&ie=utf-8&f=%5B1,12,13,14%5D&c=257&sn=0$${stations[i].UId}$$undefined,undefined$${stations[i].Name}$$&en=0$${stations[j].UId}$$undefined,undefined$${stations[j].Name}$$&m=sbw&ccode=257&from=dtzt&sy=0&t=1552814046118&callback=BMapSub._rd._cbk22197");
var index = result.IndexOf('{'); result = result.Substring(index, result.Length - index - 1);
var jResult = JsonHelper.DeserializeObject(result);
if (jResult["content"] == null) continue; var two = new TwoStationInfo { Time = jResult["content"][0]["exts"][0]["time"].Value<int>(), Distance = jResult["content"][0]["exts"][0]["distance"].Value<int>(), Price = jResult["content"][0]["exts"][0]["price"].Value<int>(), SubwayPrice = jResult["content"][0]["exts"][0]["subway_price"].Value<int>(), WalkDistance = jResult["content"][0]["exts"][0]["walk_distance"].Value<int>(), WalkTime = jResult["content"][0]["exts"][0]["walk_time"].Value<int>(), TwoStationNames = new[] { stations[i].Name, stations[j].Name } }; TwoStationInfos.Add(two);