純粋なASP.NET(ここではWCFを話しません)では、ハンドラ(ASHX)ファイルを使用してJSONをインターチェンジ形式として使用します。私はJSON(詳細はhere)の詳細には入りませんが、その考え方は、jsonのテキストを生成してクライアントに返す軽量のハンドラです.JavaScriptで構造を簡単に使用できます。
これは明らかに単純な例ですが、要点はJSONがサーバーからデータ駆動され、クライアント上のJavaScriptによって簡単に消費されるということです。
サーバー:
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/json";
context.Response.WriteFile("~/myData.json");
}
public bool IsReusable {
get {
return false;
}
}
}
クライアント:
myData =
(function()
{
var json = null;
$.ajax({
'async': false,
'global': false,
'url': "handler.ashx",
'dataType': "json",
'success': function (data) {
// this code is called when the
// data is returned from the server
json = data;
}
});
return json;
}
)();
alert(myData.MyArray[0].MyProperty);
非常に素晴らしいです。私はグスタ。 – Kris