以查询字符串转换为字典在C#中的最佳方法 [英] Best way to convert query string to dictionary in C#

查看:113
本文介绍了以查询字符串转换为字典在C#中的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找从HTTP GET请求转换成一个查询字符串转换成词典,和回来的最简单的方法。

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 manipulations on the query once it is in dictionary form, but I seem to have a lot of code just to do the conversion. Any recommended ways?

推荐答案

HttpUtility.ParseQueryString()解析查询字符串成的NameValueCollection 对象,转换后到的IDictionary<字符串,字符串> 是一个简单的问题的foreach 。然而,这可能是不必要的,因为的NameValueCollection 有一个索引,所以它的行为非常像一本字典。

HttpUtility.ParseQueryString() parses query string into a NameValueCollection object, converting the latter to an IDictionary<string, string> is a matter of a simple foreach. This, however, might be unnecessary since NameValueCollection has an indexer, so it behaves pretty much like a dictionary.

这篇关于以查询字符串转换为字典在C#中的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆