从解码的查询字符串中获取一个值

时间:2019-01-04 10:39:28

标签: c#

我有一个已编码的查询字符串,并已使用函数HttpUtility.UrlDecode(urlEncodedQueryString)对其进行了解码。解码正常,结果为:

pagesize=5&morekey=morekey&last_updated=2018-11-30 10:06:09.203&queryfilter=filter

如何获取last_updated解码查询字符串的值(即2018-11-30 10:06:09.203),以便可以将其解析为DateTime并将其用于我的进一步实施?

我尝试使用此代码,但仅返回null。

string decodedQueryString = HttpUtility.UrlDecode(urlEncodedQueryString);
var parameters = HttpUtility.ParseQueryString(decodedQueryString);

lastUpdatedDateUtc = DateTime.Parse(parameters["last_updated="]);

我希望将lastUpdatedDateUtc的值设置为2018-11-30 10:06:09.203

1 个答案:

答案 0 :(得分:1)

更改

lastUpdatedDateUtc = DateTime.Parse(parameters["last_updated="]);

lastUpdatedDateUtc = DateTime.Parse(parameters["last_updated"]); 

不应在参数名称中包含=

相关问题