J'ai une fonction avec un type de retour de liste. J'utilise cela dans un JSON compatible WebService comme:JavaScriptSerializer avec le type personnalisé
[WebMethod(EnableSession = true)] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public List<Product> GetProducts(string dummy) /* without a parameter, it will not go through */ { return new x.GetProducts(); }
ce retour:
{"d":[{"__type":"Product","Id":"2316","Name":"Big Something ","Price":"3000","Quantity":"5"}]}
Je dois utiliser ce code dans un simple fichier ASPX, donc je créé un JavaScriptSerializer:
JavaScriptSerializer js = new JavaScriptSerializer();
StringBuilder sb = new StringBuilder();
List<Product> products = base.GetProducts();
js.RegisterConverters(new JavaScriptConverter[] { new ProductConverter() });
js.Serialize(products, sb);
string _jsonShopbasket = sb.ToString();
mais il retourne sans un type:
[{"Id":"2316","Name":"Big One ","Price":"3000","Quantity":"5"}]
Est-ce que quelqu'un a la moindre idée de comment faire fonctionner la deuxième sérialisation comme la première?
Merci!
cool! ça m'aide. Merci :) –