zoukankan      html  css  js  c++  java
  • C#Json数据类型

    引用所对应框架的类库文件,下载地址:http://json.codeplex.com/

    在一般处理程序axhx中:

    引用的命名空间:

    using System.IO;
    using Newtonsoft.Json;

    using (DB2DataContext con = new DB2DataContext())
            {
                List<people> pl = con.people.ToList();
                JsonSerializer serializer = new JsonSerializer();
                StringWriter sw = new StringWriter();
                serializer.Serialize(new JsonTextWriter(sw), pl);
                string result = sw.GetStringBuilder().ToString();
                //context.Response.Write("{"msg":"","data":"" + result + ""}");
                context.Response.Write(result);
                context.Response.End();
            }

    同时还要partial一个类:

    在类外部:

    [JsonObject(MemberSerialization.OptIn)]

    每条属性之前: 

    [JsonProperty]

    这样才能使数据有内容,如:

    [JsonObject(MemberSerialization.OptIn)]
    public partial class people
    {
        [JsonProperty]
        public string names
        {
            get
            {
                return this._name;
            }
        }
    
        [JsonProperty]
        public string birthdays
        {
            get
            {
                return this._birthday.Value.ToString("yyyy年MM月dd日");
            }
        }
        [JsonProperty]
        public string sexs
        {
            get
            {
                return this._sex.Value ? "" : "";
            }
        }
    }
  • 相关阅读:
    B树
    23查找树和红黑树
    红黑树---满足红黑性质的二叉查找树
    AVL树---平衡的二叉查找树
    二叉查找树
    Ping程序
    ICMP:Internet控制报文协议
    Unix&Linux大学教程目录
    Linux文件系统
    git简介
  • 原文地址:https://www.cnblogs.com/zJuevers/p/8478519.html
Copyright © 2011-2022 走看看