何が欠けているのか、どこが間違っているのかわかりません。
ASP.NET 2.0(.Net 3.5フレームワーク上)Webアプリケーションを構築しており、Webサービスを組み込んでいます。これはMVCプロジェクトではないことに注意してください。JSON文字列を返すメソッドを公開したいと思います。jqGridjQueryプラグインをフィードするようにフォーマットされています。
これは、私がサービスに実装した予備テスト方法です。(Phil Haackの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();
}
呼び出されると、これが返されます(わかりやすくするためにフォーマットされています)。
<?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>
xmlラッピングなしで上記の応答をどのように達成しますか?