title: WebMethod returning JSON object issue
body: <p>I am struggling to get object handled properly when returned from WebMethod.
  Conditions (my research after it):</p>
  
  <p>Simple class to hold the properties:</p>
  
  <pre class="lang-cs prettyprint-override"><code>    public class memberLogin
      {
      public string Username {get; set;}
      public string Password {get; set;}
      }
  </code></pre>
  
  <p>Serialization method:</p>
  
  <pre class="lang-cs prettyprint-override"><code>        public static string JsonSerializer&lt;T&gt;(T t)
          {
              DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
              MemoryStream ms = new MemoryStream();
              ser.WriteObject(ms, t);
              string jsonString = Encoding.UTF8.GetString(ms.ToArray());
              ms.Close();
              return jsonString;
          }
  </code></pre>
  
  <p>(simplified for clearness) Webmethod</p>
  
  <pre class="lang-cs prettyprint-override"><code>    [WebMethod(EnableSession = true)]
      public static string getCredentials()
          {
              memberLogin ml = new memberLogin();
              ml.Username = "user";
              ml.Password = "pass";
              string json = JsonHelper.JsonSerializer&lt;memberLogin&gt;(ml);
              return json;
          }
          return null;
      }
  </code></pre>
  
  <p>And JavaScript</p>
  
  <pre class="lang-js prettyprint-override"><code>$("#element").live("click", function (e) { 
  
  $.ajax({
      type: "POST",
      url: "Default.aspx/getCredentials",
      data: "{}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      async: false,
      cache: false,
      success: post_to_url
  });
  });
  function post_to_url(params) {
  method = "post";
  path = "http://example";
  
  var form = document.createElement("form");
  form.setAttribute("method", method);
  form.setAttribute("action", path);
  
  for(var key in params) {
      if(params.hasOwnProperty(key)) {
          var hiddenField = document.createElement("input");
          hiddenField.setAttribute("type", "hidden");
          hiddenField.setAttribute("name", key);
          hiddenField.setAttribute("value", params[key]);
  
          form.appendChild(hiddenField);
       }
  }
  document.body.appendChild(form);
  form.submit();
  }
  </code></pre>
  
  <p>When debugging, WebMethod returns <code>"{\"Password\":\"pass\",\"Username\":\"user\"}"</code> so it seems to be what I want it to be (key, value par), except the <code>\</code> but that is how it is serialized.
  However when retrieved using ajax, I can not get any values out of it. <code>alert(params)</code> gives <code>object Object</code>, call to params.Username gives <code>undefined</code>. Is there something I am missing? Some sort of cast?
  I thought that if object is serialized, then there's no such need.
  Sorry for very long post but I tried to provide as much informations as I could.</p>