Asp.net 利用微软的自带方法 object to json

<%@ WebHandler Language="C#" Class="pie1" %>

using System;
using System.Web;
using System.Collections;
using System.Text;
using System.Collections.Generic;
using Uzai.Shop.Entity;
using Uzai.Shop.BLL.BLLYDL;
using System.Linq;
using System.Web.Script.Serialization;

public class pie1 : IHttpHandler {

    YouDaoLv bll = new YouDaoLv();
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        DateTime sD = context.Request["s"] == null ? new DateTime(1900, 1, 1) : Convert.ToDateTime(context.Request["s"]);
        DateTime eD = context.Request["e"] == null ? new DateTime(1900, 1, 1) : Convert.ToDateTime(context.Request["e"]);
        string pCode = context.Request["pCode"] == null ? string.Empty : context.Request["pCode"];

        ArrayList datalist = new ArrayList();
        List<YoudaolvDetail> list = new List<YoudaolvDetail>();
        list = bll.GetPieData(sD, eD, pCode).OrderByDescending(m=>m.YoudaoNum).ToList();

        JavaScriptSerializer json = new JavaScriptSerializer();
        string a = json.Serialize(list);

        context.Response.Clear();
        context.Response.Write(a);
        context.Response.End();
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}


序列化 后结果:

Asp.net 利用微软的自带方法 object to json_第1张图片


其它的参考文章:

DataTable to json      http://www.360doc.com/content/10/0129/11/109051_14651431.shtml     

json 序列化 和 反序列化 http://www.cnblogs.com/zhaozhan/archive/2011/01/09/1931340.html

你可能感兴趣的:(Asp.net 利用微软的自带方法 object to json)