当前位置:编程学习 > JS >>

C#编程操作JSON实例代码

实例代码如下:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Newtonsoft.Json;
  5. namespace TestJson
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string json = "{"a":"sadsad","c":{"d":"adad"}}";
  12.             //CCC ccc = new CCC();
  13.             //ccc.d = "adad";
  14.             //AAA aaa = new AAA();
  15.             //aaa.a = "sadsad";
  16.             //aaa.b = "dfgdg";
  17.             //aaa.c = ccc;
  18.             AAA aaa = new AAA();
  19.             aaa= JavaScriptConvert.DeserializeObject(json);
  20.            // string json = JavaScriptConvert.SerializeObject(aaa);
  21.            // Console.WriteLine(json);
  22.             Console.Read();
  23.         }
  24.     }
  25.     public class AAA {
  26.     
  27.         private string m_a;
  28.         public string a
  29.         {
  30.             get { return m_a; }
  31.             set { m_a = value; }
  32.         }
  33.         private string m_b;
  34.         public string b
  35.         {
  36.             get { return m_b; }
  37.             set { m_b = value; }
  38.         }
  39.         private CCC m_c;
  40.         public CCC c
  41.         {
  42.             get { return m_c; }
  43.             set { m_c = value; }
  44.         }
  45.     }
  46.    
  47.     public class CCC
  48.     {
  49.         private string m_d;
  50.         public string d
  51.         {
  52.             get { return m_d; }
  53.             set { m_d = value; }
  54.         }
  55.     }
  56. }
补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,