Best way to convert query string to dictionary in C#

前端 未结 13 878
温柔的废话
温柔的废话 2020-12-24 04:28

I\'m looking for the simplest way of converting a query string from an HTTP GET request into a Dictionary, and back again.

I figure it\'s easier to carry out various

相关标签:
13条回答
  • 2020-12-24 05:29

    Yet another way to do it:

    NameValueCollection nvcData = HttpUtility.ParseQueryString(queryString);
    Dictionary<string, string> dictData = new Dictionary<string, string>(nvcData.Count);
    foreach (string key in nvcData.AllKeys)
    {
        dictData.Add(key, nvcData.Get(key));
    }
    
    0 讨论(0)
提交回复
热议问题