使用 一般处理程序(ashx)返回Json值。
原始Json数组的格式:
[ { "number":"01", "name":"张三", "sex":"男" }, { "number":"02", "name":"李四", "sex":"男" }, { "number":"03", "name":"小明", "sex":"女" } ]
//----------
其中,双引号【""】在C#中不能直接拼接,而又不能使用单引号【'】,所以要加上转义字符【】。格式如下:
//----------
格式化之后Json:
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; StringBuilder strjson = new StringBuilder(); strjson.Append("["); strjson.Append("{"number":"01","name":"张三","sex":"男"}"); strjson.Append(","); strjson.Append("{"number":"02","name":"李四","sex":"男"}"); strjson.Append(","); strjson.Append("{"number":"02","name":"王五","sex":"女"}"); strjson.Append("]"); context.Response.Write(strjson); }