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;
        }
    }

}


序列化 后结果:


其它的参考文章:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值