ASP.NET JSON de Réponse du Service Web format

J'ai écrit un service web simple qui se produit liste dans JSONText qui est l'objet de corde

Service Web code est ci-dessous

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;
///<summary>
///Summary description for JsonWebService
///</summary>
[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<Product> products = new List<Product>();
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;
}
}

maintenant il me donner resoponse comme ci-dessous :

{"d":"[{\"ProductID\":1,\"Nom\":\"1\"},{\"ProductID\":2,\"Nom\":\"Produit 2\"},{\"ProductID\":3,\"Nom\":\"Produit 3\"},{\"ProductID\":4,\"Nom\":\"4\"},{\"ProductID\":5,\"Nom\":\"Produit 5\"},{\"ProductID\":6,\"Nom\":\"Produit 6\"},{\"ProductID\":7,\"Nom\":\"Produit 7\"},{\"ProductID\":8,\"Nom\":\"Produit 8\"},{\"ProductID\":9,\"Nom\":\"Produit 9\"},{\"ProductID\":10,\"Nom\":\"Produit 10\"}]"}

Mais je suis à la recherche de ci-dessous mettre à

[{"ProductID":1,"Nom":"1"},{"ProductID":2,"Nom":"Produit 2"},{"ProductID":3,"Nom":"Produit 3"},{"ProductID":4,"Nom":"4"},{"ProductID":5,"Nom":"Produit 5"},{"ProductID":6,"ProductName":Produit "6"},{"ProductID":7,"Nom":"Produit 7"},{"ProductID":8,"Nom":"Produit 8"},{"ProductID":9,"Nom":"Produit 9"},{"ProductID":10,"Nom":"Produit 10"}]

quelqu'un peut-il me dire ce qui est réel problème

Grâce

OriginalL'auteur Hiscal | 2009-08-06