title: ASP.NET JSON Web Service Response format
body: <p>I have written one simple web service which get product list in JSONText which is string object </p>
  
  <p>Web Service code is below </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Web;
  using System.Web.Services;
  using System.Web.Script.Services;
  using System.Runtime.Serialization.Json;
  using System.IO;
  using System.Text;
  
  /// &lt;summary&gt;
  /// Summary description for JsonWebService
  /// &lt;/summary&gt;
  [WebService(Namespace = "http://tempuri.org/")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  [System.Web.Script.Services.ScriptService]
  public class JsonWebService : System.Web.Services.WebService 
  {
  
      public JsonWebService () {
  
          //Uncomment the following line if using designed components 
          //InitializeComponent(); 
      }
  
      [WebMethod]
      [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
      public string GetProductsJson(string prefix) 
      {
          List&lt;Product&gt; products = new List&lt;Product&gt;();
          if (prefix.Trim().Equals(string.Empty, StringComparison.OrdinalIgnoreCase))
          {
              products = ProductFacade.GetAllProducts();
          }
          else
          {
              products = ProductFacade.GetProducts(prefix);
          }
          //yourobject is your actula object (may be collection) you want to serialize to json
          DataContractJsonSerializer serializer = new DataContractJsonSerializer(products.GetType());
          //create a memory stream
          MemoryStream ms = new MemoryStream();
          //serialize the object to memory stream
          serializer.WriteObject(ms, products);
          //convert the serizlized object to string
          string jsonString = Encoding.Default.GetString(ms.ToArray());
          //close the memory stream
          ms.Close();
          return jsonString;
      }
  }
  </code></pre>
  
  <p><strong>now it give me resoponse like below :</strong> </p>
  
  <p>{"d":"[{\"ProductID\":1,\"ProductName\":\"Product 1\"},{\"ProductID\":2,\"ProductName\":\"Product 2\"},{\"ProductID\":3,\"ProductName\":\"Product 3\"},{\"ProductID\":4,\"ProductName\":\"Product 4\"},{\"ProductID\":5,\"ProductName\":\"Product 5\"},{\"ProductID\":6,\"ProductName\":\"Product 6\"},{\"ProductID\":7,\"ProductName\":\"Product 7\"},{\"ProductID\":8,\"ProductName\":\"Product 8\"},{\"ProductID\":9,\"ProductName\":\"Product 9\"},{\"ProductID\":10,\"ProductName\":\"Product 10\"}]"}</p>
  
  <p><strong>But i am looking for below out put</strong> </p>
  
  <p>[{"ProductID":1,"ProductName":"Product 1"},{"ProductID":2,"ProductName":"Product 2"},{"ProductID":3,"ProductName":"Product 3"},{"ProductID":4,"ProductName":"Product 4"},{"ProductID":5,"ProductName":"Product 5"},{"ProductID":6,"ProductName":"Product 6"},{"ProductID":7,"ProductName":"Product 7"},{"ProductID":8,"ProductName":"Product 8"},{"ProductID":9,"ProductName":"Product 9"},{"ProductID":10,"ProductName":"Product 10"}]</p>
  
  <p>can any one tell me what is actual problem </p>
  
  <p>Thanks</p>