Webclient 的查询字符串到 json 字符串 - c#

Query string of Webclient to json string - c#

我正在使用以下查询将数据发送到 webAPI。它工作正常。如何将我使用的查询字符串转换为此函数中的 json 字符串?可能吗?

        WebClient wc = new WebClient();

        wc.Headers.Add("Authorization", "Bearer " + token);
        wc.QueryString.Add("unique_id", (checklist_ID.ToString()));
        wc.QueryString.Add("Question_no", (QNO.ToString()));
        wc.QueryString.Add("Question", t1_question.Text.ToString());
        wc.QueryString.Add("Password", t1_password.Text.ToString());

        var data = wc.UploadValues(url, "POST", wc.QueryString);

         //here I want this Querystring data in below json format 
         // [{"unique_id":"2233","Question_no":"43","Question":"XXXX??","Password":"testpswd"}]

        var responseString = UnicodeEncoding.UTF8.GetString(data);

使用LinqJsonConvert得到想要的结果

//Use LINQ to convert the QueryString to Dictionary
var keyValuePairs = (
        from key in wc.QueryString.AllKeys
        from value in wc.QueryString.GetValues(key)
        select new { key, value }).ToDictionary(x => x.key, x => x.value);

//Use Newtonsoft.Json to Serialize the object to json format
Console.WriteLine(JsonConvert.SerializeObject(keyValuePairs));