zoukankan      html  css  js  c++  java
  • json.net的常用语句JsonConvert.SerializeObject(对象)

      在ajax的已不请求中,常常返回json对象。可以利用json.net给我们提供的api达到快速开发。

    B.cs

        public class B
        {
           public B(){}
             private int money = 0;
               private string name = string.Empty;
               public int Money
              {
                  get { return money; }
                  set { money = value; }
             }
              public string Name
            {
                  get { return name; }
                  set { name = value; }
            }
        }

    A.cs:

        public class A
        {
           public A(){}
              public int age { get; set; }
                public string name { get; set; }
                B b = null;

                  public B B
              {
                  get { return b; }
                  set { b = value; }
              } 
        }

     测试代码如下:

     using Newtonsoft.Json;

     protected void Page_Load(object sender, EventArgs e)
        {
            A a = new A();
            a.age = 11;
            a.name = "Name";
            B b = new B();
            b.Money = 10000;
            //b.Name = "小样";
            a.B = b;
           string str= JsonConvert.SerializeObject(a);
           Response.Write(str);
        }

     输出:{"age":11,"name":"Name","B":{"Money":10000,"Name":""}}

  • 相关阅读:
    PCI配置空间与IO空间与内存空间
    python读配置文件,根据配置文件内容改写二进制文件
    python参数的传递机制
    python复制、移动文件到指定文件夹
    python解析配置文件
    python struct用法
    Python 字符串前面加u,r,b的含义
    shell算数运算符
    三、shell -break、continue、exit、return
    shell-逻辑判断
  • 原文地址:https://www.cnblogs.com/langlang/p/1622267.html
Copyright © 2011-2022 走看看