zoukankan      html  css  js  c++  java
  • Json.NET 应用

    首先介绍一个为方便在.NET中使用JSON的API,Json.NET。它方便我们读取从浏览器流向服务器的JSON对象,也方便在响应流中写入JSON对象。

    在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":""}}

  • 相关阅读:
    USB 之传输编码格式 NRZI 介绍
    ubuntu 14.04 安装中文输入法
    uart 超声波传感器数据读取
    Embarcadero Delphi 7 Lite 7.0.4.453 中文版
    Delphi连接Oracle控件ODAC的安装及使用
    ODAC 安裝 (11.2.4)
    Sql中CHARINDEX用法
    DELPHI 数据库控件心得
    delphi uniDac
    Delphi连接Oracle控件ODAC的安装及使用
  • 原文地址:https://www.cnblogs.com/martin1009/p/2231407.html
Copyright © 2011-2022 走看看