Sample.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Sample.aspx.cs" Inherits="Sample" %>
Json.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json.aspx.cs" Inherits="Json" %>
Json.aspx.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Script.Serialization; public partial class Json : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { JavaScriptSerializer serializer = new JavaScriptSerializer(); var responseEntities = new List() { new Person{ Name="帳務清冊.xlsx", Id="Id1"}, new Person{ Name="程式筆記.docx", Id="Id2"}, new Person{ Name="客戶名單.xlsx", Id="Id3"}, new Person{ Name="心得分享.pptx", Id="Id4"} }; var result = serializer.Serialize(responseEntities); Response.Write(result); Response.End(); } } public class Person { public string Name { get; set; } public string Id { get; set; } }
範例下載
沒有留言:
張貼留言