介绍
Flash ActionScript 3.0 以文本形式与ASP.NET通信、以XML形式与ASP.NET通信和以JSON形式与ASP.NET通信
示例
Text.aspx.cs
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?Text?:?System.Web.UI.Page
{
????protected?void?Page_Load(object?sender,?EventArgs?e)
????{
????????string?s?=?"name:?"?+?Request.QueryString["name"]?+?";?age:?"?+?Request.QueryString["age"];
????????Response.ClearContent();
????????Response.ContentType?=?"text/plain";
????????Response.Write(s);
????????Response.End();
????}
}
Xml.aspx.cs
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?Xml?:?System.Web.UI.Page
{
????protected?void?Page_Load(object?sender,?EventArgs?e)
????{
????????string?s?=?@"<?xml?version=""1.0""?encoding=""utf-8""?>
????????????<root>
????????????????<person?name=""webabcd""?age=""27"">
????????????????????<salary>1000</salary>
????????????????</person>
????????????????<person?name=""webabcdefg""?age=""37"">
????????????????????<salary>2000</salary>
????????????????</person>
????????????????<person?name=""webabcdefghijklmn""?age=""47"">
????????????????????<salary>3000</salary>
????????????????</person>
????????????</root>";
????????Response.ClearContent();
????????Response.ContentType?=?"text/xml";
????????Response.Write(s);
????????Response.End();
????}
}
JSON.aspx.cs
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]
http:/