C#将URL中的参数转换成字典Dictionary<string, string>

        public static Dictionary UrlToDictionary(this string s)
        {

            var dic = new Dictionary();

            if (s.Contains("&") || s.Contains("="))
            {
                var args = HttpUtility.ParseQueryString(s);
                if (args == null || args.Count <= 0) { return dic; }
                foreach (var key in args.AllKeys)
                {
                    if (key == null) { continue; }
                    if (dic.ContainsKey(key))
                    {
                        dic[key] = args[key];
                    }
                    else
                    {
                        dic.Add(key, args[key]);
                    }

                }

            }

            return dic;

        }

你可能感兴趣的:(其他,java,前端,开发语言,c#)