首页 > Windows开发 > 详细

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

时间:2021-09-02 04:20:58      阅读:16      评论:0      收藏:0      [点我收藏+]

例如:

<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>值

原文:https://www.cnblogs.com/shiaguang/p/15213958.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!