title: JSON string wrapped in double quotes - Can't write out values from JSON string - (asp.net webservice to JSON to jQuery)
body: <p>Im trying to use a asp.net webservice to send JSON data, which it gets from a MySql database, to a web app, which uses jQuery to display the data sent through JSON.</p>
  
  <p>My webservice method looks like this:</p>
  
  <pre><code>[WebMethod(Description = "yet another test .....")]
  [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
  public string GetCustomerByIDTRY()
  {
  string connString = System.Configuration.ConfigurationManager.ConnectionStrings["my_domain_mysql"].ConnectionString;
  MySqlConnection connection1 = new MySqlConnection(connString);
  MySqlCommand cmd = new MySqlCommand("SELECT Vet_Users.FirstName, Vet_Users.LastName, Vet_Users.UserID, Vet_Customer.CusID FROM Vet_Users JOIN Vet_Customer ON Vet_Users.UserID=Vet_Customer.UserID");
  DataSet CusIDDataSet = new DataSet();
  MySqlDataAdapter CusIDDataAdapter = new MySqlDataAdapter(cmd);
  CusIDDataAdapter.SelectCommand.Connection = connection1;
  CusIDDataAdapter.Fill(CusIDDataSet, "reading");
  connection1.Close();
  StringBuilder JSON = new StringBuilder();
  JSON.Append("{");
  JSON.Append("\"NumberOfCustomers\":\"" + CusIDDataSet.Tables[0].Rows.Count.ToString() + "\", ");
  JSON.Append("\"Customer\":[");
  foreach (DataRow rs in CusIDDataSet.Tables[0].Rows)
  {
  JSON.Append("{");
  JSON.Append("\"CusID\":\"" + rs["CusID"].ToString() + "\",");
  JSON.Append("\"FirstName\":\"" + rs["FirstName"].ToString() + "\",");
  JSON.Append("\"LastName\":\"" + rs["LastName"].ToString() + "\",");
  if (JSON.ToString().EndsWith(","))
  JSON = JSON.Remove(JSON.Length - 1, 1);
  JSON.Append("},");
  }
  if (JSON.ToString().EndsWith(","))
  JSON = JSON.Remove(JSON.Length - 1, 1);
  JSON.Append("]}");
  return JSON.ToString();
  }
  </code></pre>
  
  <p>The JSON comes back like this:</p>
  
  <pre><code>Object { d="{"NumberOfCustomers":"1...","LastName":"Woods"}]}"}
  </code></pre>
  
  <p>Its wrapped in a "d", cause of asp.net 3.5+ security issue.
  (<a href="http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/" rel="nofollow">http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/</a>)</p>
  
  <p>But my JSON comes wrapped in double quotes, and i can't figure out why.</p>
  
  <pre><code>"{"NumberOfCustomers":"15", "Customer":[{"CusID":"1","FirstName":"Ina","LastName":"Williamson"},{"CusID":"2","FirstName":"Hyacinth","LastName":"Brady"},{"CusID":"3","FirstName":"Coby","LastName":"Shannon"}]}"
  </code></pre>
  
  <p>This is the jQuery function, that im trying to get working:</p>
  
  <p><code>   function FinalTest() {
      $.ajax({
      type: "POST",
      url: "url",
      data: "{}", 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      success: function (data) {
      alert(eval(data.d.NumberOfCustomers));
      }
      });
      };</code></p>