日期:2014-05-16 浏览次数:20393 次
protected void Page_Load(object sender, EventArgs e)
{
string userName = string.IsNullOrEmpty(Request.QueryString["userName"]) ? "" : Request.QueryString["userName"].ToString();
int age = string.IsNullOrEmpty(Request.QueryString["age"]) ? 0 : Convert.ToInt32(Request.QueryString["age"]);
string address = "s;'d\\\\\\\"fs;dfk";
StringBuilder sb = new StringBuilder();
sb.Append("{");
sb.AppendFormat("\"userName\":\"{0}\",\"age\":\"{1}\",\"address\":\"{2}\"", userName, age, address);
sb.Append("}");
Response.Write(sb.ToString());
}
<script type="text/javascript">
$(function () {
$.ajax({
type: "GET",
url: "Ajax/Demo.aspx",
data: "userName=qingyun",
success: function (data) {
alert("userName=" + data.userName);
alert("age=" + data.age);
alert("address=" + decodeURIComponent(data.address));
},
error: function (red) {
alert("error");
},
dataType: "json"
});
});
</script>
sb.Append("{");
sb.AppendFormat("\"userName\":\"{0}\",\"age\":\"{1}\",\"address\":\"{2}\"", userName, age, address);
sb.Append("}");