WEB开发网
开发学院图形图像Flash 积少成多Flash(3) - ActionScript 3.0 基础之以文... 阅读

积少成多Flash(3) - ActionScript 3.0 基础之以文本形式、XML形式和JSON形式与ASP.NET通信

 2009-11-05 00:00:00 来源:WEB开发网   
核心提示: JSON.aspx.csusingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.

JSON.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class JSON : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Person person = new Person();
        person.Name = "webabcd";
        person.Age = 27;
        HttpContext.Current.Response.ClearContent();
        // HttpContext.Current.Response.ContentType = "application/json";
        HttpContext.Current.Response.ContentType = "text/plain";
        // 把person对象序列化成JSON
        System.Runtime.Serialization.DataContractJsonSerializer dcjs = new System.Runtime.Serialization.DataContractJsonSerializer(person.GetType());
        dcjs.WriteObject(HttpContext.Current.Response.OutputStream, person);
        HttpContext.Current.Response.End();
    }
}
/**//// <summary>
/// Person类
/// </summary>
[System.Runtime.Serialization.DataContract]
public class Person
{
    private string _name;
    /**//// <summary>
    /// 姓名
    /// </summary>
    [System.Runtime.Serialization.DataMember]
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
    private int _age;
    /**//// <summary>
    /// 年龄
    /// </summary>
    [System.Runtime.Serialization.DataMember]
    public int Age
    {
        get { return _age; }
        set { _age = value; }
    }
}

Tags:积少成多 Flash ActionScript

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接