Non sono sicuro di dove sto andando male di quello che mi manca.ASP.NET WebService sta avvolgendo la mia risposta JSON con i tag XML
Sto costruendo un'applicazione Web ASP.NET 2.0 (sul .Net 3.5 framework) e includo un servizio web. Si noti che questo è non un progetto MVC. Vorrei esporre un metodo che restituirà una stringa JSON; formattato per alimentare il plugin jQuery jqGrid.
Questo è il metodo di prova preliminare Ho implementato nel mio servizio: grazie a (Phil Haack's Guide for MVC)
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string getData()
{
JavaScriptSerializer ser = new JavaScriptSerializer();
var jsonData = new
{
total = 1, // we'll implement later
page = 1,
records = 3, // implement later
rows = new[]{
new {id = 1, cell = new[] {"1", "-7", "Is this a good question?", "yay"}},
new {id = 2, cell = new[] {"2", "15", "Is this a blatant ripoff?", "yay"}},
new {id = 3, cell = new[] {"3", "23", "Why is the sky blue?", "yay"}}
}
};
return ser.Serialize(jsonData); //products.ToString();
}
Quando viene richiamato questo sta ritornando (formattato per chiarezza):
<?xml version="1.0" encoding="utf-8" ?>
<string mlns="http://tempuri.org/">
{
"total":1,
"page":1,
"records":3,
"rows":
[
{"id":1,"cell":["1","-7","Is this a good question?","yay"]},
{"id":2,"cell":["2","15","Is this a blatant ripoff?","yay"]},
{"id":3,"cell":["3","23","Why is the sky blue?","yay"]}
]
}
</string>
Come sarebbe Otterrò la risposta sopra senza gli involucri xml?
Come hai ottenuto il risultato. Quando implemento il tuo aspetto, sembra che restituisca "[oggetto oggetto]". Questo potrebbe essere ingenuo per JSON, ma non riesco a farlo funzionare. – Mike
Ho usato firebug in Firefox per visualizzare la risposta dal pannello Rete: fare clic sulla scheda risposta per quella richiesta. –
Sapete perché i dati vengono inclusi nella variabile "d"? – Mike