title: Serialize querystring as Json in C#- values don't show up, only the keys. Why?
body: <p>I'm trying to serialize a querystring to JSON in C#. I'm not getting the results I expected, and am hoping someone can explain. Some reason I'm only getting the query "name" and not the "value".</p>
  
  <pre><code>   //Sample Query:
     http://www.mydomain.com/Handler.ashx?method=preview&amp;appid=1234      
  
  
      //Generic handler code:
      public void ProcessRequest(HttpContext context)
      {
          string json = JsonConvert.SerializeObject(context.Request.QueryString);
          context.Response.ContentType = "text/plain";
          context.Response.Write(json);
      }
  
      //Returns something like this:
      ["method", "appid"]
  
      //I would expect to get something like this:
      ["method":"preview", "appid":"1234"]
  </code></pre>
  
  <p>Anyone know how to get a string resembling the latter sample output? I've also tried</p>
  
  <pre><code>string json = new JavaScriptSerializer().Serialize(context.Request.QueryString);
  </code></pre>
  
  <p>and gotten identical results as the Newtonsoft Json.</p>
  
  <p>EDIT- Here's the final working code based on the answer below:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Script.Serialization;
  using Newtonsoft.Json;
  using System.Collections.Specialized;
  
  namespace MotoAPI3
  {
  
  public class Json : IHttpHandler
  {
  
      public void ProcessRequest(HttpContext context)
      {
          var dict = new Dictionary&lt;string, string&gt;();
          foreach (string key in context.Request.QueryString.Keys)
          {
              dict.Add(key, context.Request.QueryString[key]);
          }
  
          string json = new JavaScriptSerializer().Serialize(dict);
          context.Response.ContentType = "text/plain";
          context.Response.Write(json);
      }
  
      public bool IsReusable
      {
          get
          {
              return false;
          }
      }
  }
  </code></pre>