using System;
using System.Web;
using System.Text;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string id = "";
//判断提交方式
if (context.Request.RequestType.ToLower() == "get")
{
id = context.Request.QueryString["id"];
}
else
{
id = context.Request.Form["id"];
}
string name = @"jinho's good \"" you";
/**
* 今天暂时用手动创建个json字符串类型,其实.net中有
* System.Runtime.Serialization.Json.DataContractJsonSerializer这个类来把
* 实体对象转换为json字符串! 改天再用那种方式写个吧!
* 自己也学习学习[更多关于json介绍!google一下多了是]
* */
StringBuilder sb = new StringBuilder("{");
sb.Append("id:"+id);
/*
* 注意但属性值为字符串的时候需要有'号或者"号['字符串']
* 当 参数 name 又含 有单引号或者双引号 就会出错了![截断了字符串]
* 在这里sb.Append(",name:'escape(" + name + ")'"); 用js的escape也不行
* context.Server.HtmlEncode();,context.Server.UrlEncode();也不行
* 可以看看这里
* escape(&