C#取XML

例如:

<ArrayOfString xmlns:xsi="#" xmlns:xsd="#" xmlns="#">
<string>1</string>
<string>2</string>
<string>3</string>
</ArrayOfString>
 
 public async Task<WeatherContext> Weather(string city)
        {
            var client = new RestClient(_config["Weatherurl"]+ city);
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            IRestResponse response = client.Execute(request);
            string[] s = new string[3];//声明string数组存放返回结果  
            string bl = "";
            string z = response.Content;
            int k = 0;
            bool b = true;
            for (int i = 0; i < z.Length-8; i++)
            {

                if (b)
                {
                    bl = z.Substring(i, 8);
                }
                if (bl.Equals("<string>"))
                {
                    if (z.Substring(i+8,1)!="<")
                    {
                        b = false;
                        s[k] += z.Substring(i + 8, 1);
                    }
                    else
                    {
                        b = true;
                        k++;
                        i += 8;
                    }
                    
                }
            }
            WeatherContext weather = new WeatherContext
            {
                1 = s[0],
                2 = s[1],
                3 = s[2],
            };
            return weather;
        }

 

C#取XML<string></string>值

上一篇:C#/.NET中借助 Newtonsoft.Json 返回给前端json强制使用小写格式


下一篇:jest not implemented window.open()