Ho una funzione con un tipo di ritorno Elenco. Sto usando questo in un WebService JSON-enabled come:JavaScriptSerializer con tipo personalizzato
[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(); }
restituisce:
{"d":[{"__type":"Product","Id":"2316","Name":"Big Something ","Price":"3000","Quantity":"5"}]}
ho bisogno di utilizzare questo codice in un semplice file aspx troppo, così ho creato 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();
ma restituisce senza un tipo:
[{"Id":"2316","Name":"Big One ","Price":"3000","Quantity":"5"}]
Qualcuno ha qualche idea su come ottenere il secondo lavoro di serializzazione come il primo?
Grazie!
freddo! mi aiuta. Grazie :) –