HttpUtility.ParseQueryString value and Key

本文关键字:Key and value ParseQueryString HttpUtility | 更新日期: 2023-09-27 18:32:12

>我正在尝试删除 HttpUtility.ParseQueryString 的键和值,但我无法获取键和值。(例如://somesite.com/someaction?article=1&lang=en )

我想要这样的东西:

           [
            {"article",1}, 
            {"lang","en"}
           ];

知道如何到达那里吗?

HttpUtility.ParseQueryString value and Key

您可以获取所有键和值:

string[] allKeys = Request.QueryString.AllKeys
    .Select(k => "key: " + k + " value: " + Request.QueryString[k])
    .ToArray();

修改 Select 方法以获取所需的数据结构(string[] 除外),例如:

string[][] allKeys = Request.QueryString.AllKeys
    .Select(k => new string[] { k, Request.QueryString[k]})
    .ToArray();