Ho un WebMethod che assomiglia a questo che viene utilizzato per popolare un jqGridCome faccio WebMethods serializzare ExpandoObject
[System.Web.Script.Services.ScriptService]
public class MyWebService: System.Web.Services.WebService
{
[WebMethod]
[Authorize(Roles = "Admin")]
public object GetPeople(bool _search, double nd, int rows, int page, string sidx, string sord)
{
var tbl = new DynamicModel("ConnStr", tableName: "Person", primaryKeyField: "ID");
var results = tbl.Paged(orderBy: sidx + " " + sord, currentPage: page, pageSize: rows);
return results;
}
}
"risultati" è una System.Dynamic.ExpandoObject con le proprietà Items, TotalPages, TotalRecords
jSON torno sulla dal webservice assomiglia a questo
{
"d": [{
"Key": "TotalRecords",
"Value": 1
}, {
"Key": "TotalPages",
"Value": 1
}, {
"Key": "Items",
"Value": [
[{
"Key": "Row",
"Value": 1
}, {
"Key": "ID",
"Value": 1
}, {
"Key": "Name",
"Value": "Test Template"
}]
]
}]
}
} // Don't know why firebug put this extra bracket
Idealmente preferirei che ritorna senza tutte le attività chiave e il valore in quanto contribuisce ad appesantire fuori il json inutilmente e non gioca bene con jqGrid.
C'è un modo per modificare il modo in cui ASP.NET gestisce la serializzazione di ExpandoObject?
Un amico consigliato questo approccio http://stackoverflow.com/questions/5156664/how-to-flatten-an-expandoobject-returned-via-jsonresult-in-asp -net-mvc ma non so come registrare JavaScriptConverter con JavaScriptSerializer che il noi usi di bmethod. –
Accidenti, la risposta che cerco è qui http://msdn.microsoft.com/en-us/library/bb763183.aspx a circa metà strada –
Buono a sapersi che hai imparato qualcosa di nuovo :) – Jull