查询天气免费Api

            var url = "http://wthrcdn.etouch.cn/WeatherApi?city=" + HttpUtility.UrlDecode(city);
            var client = this.httpClientFactory.CreateClient(nameof(HttpClient));
            var response = await client.GetAsync(url);
            var xml = await response.Content.ReadAsStringAsync();
            XmlDocument doc = new XmlDocument();
            xml = Regex.Replace(xml, @"<\?xml*.*?>", "", RegexOptions.IgnoreCase);
            doc.LoadXml(xml);
            string jsonText = JsonConvert.SerializeXmlNode(doc);
            var jsonObj = JsonConvert.DeserializeObject<dynamic>(jsonText);

 

posted @ 2021-08-02 14:00  b̶i̶n̶g̶.̶  阅读(45)  评论(0编辑  收藏  举报