• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C#对json对象嵌套数组

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

看图:

这里可以看到是二层嵌套!!使用C#如何实现??

思路:使用list集合实现 → 建立类 → list集合 → 微软的   Newtonsoft.Json  (一款.NET中开源的Json序列化和反序列化)

sonXMText类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JsonDemo
{
    public class sonXMText
    {
        public string xmleixing { get; set; }

        public string count { get; set; }

        public string xmtype { get; set; }

        public string url { get; set; }

        public string progress { get; set; }

        public string WaitCount { get; set; }
    }
}

TestInfo类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JsonDemo
{
    public class TestInfo
    {
        public string XMText { get; set; }

        public string XMTYPE { get; set; }

        public string Count { get; set; }

        List<sonXMText> sonxmtext = new List<sonXMText>();
        public List<sonXMText> sonXMText
        {
            get { return sonxmtext; }
            set { sonxmtext = value; }
        }
    }
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JsonDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            List<TestInfo> listTestinfo = new List<TestInfo>();
            TestInfo testinfo = new TestInfo();
            testinfo.XMText = "综合交通";
            testinfo.XMTYPE = "01";
            testinfo.Count = "108";

            List<sonXMText> listSonText = new List<sonXMText>();
            sonXMText sontext1 = new sonXMText();
            sontext1.xmleixing = "市重点交通";
            sontext1.xmtype = "32";
            sontext1.count = "20";
            sontext1.url = "../ProjectManage/Pagesilding/ZongHeJiaoTong/Zonghetra/Zonghetra_List.aspx?xmtype=0101";
            sontext1.progress = "52.61";
            sontext1.WaitCount = "27";

            sonXMText sontext2 = new sonXMText();
            sontext1.xmleixing = "支路网建设";
            sontext1.xmtype = "32";
            sontext1.count = "20";
            sontext1.url = "../ProjectManage/Pagesilding/ZongHeJiaoTong/Zonghetra/Zonghetra_List.aspx?xmtype=0101";
            sontext1.progress = "52.61";
            sontext1.WaitCount = "27";

            listSonText.Add(sontext1);
            listSonText.Add(sontext2);
            testinfo.sonXMText = listSonText;

            listTestinfo.Add(testinfo);

            string aa = Newtonsoft.Json.JsonConvert.SerializeObject(listTestinfo);
            File.AppendAllText(@"C:\mymiao.txt", aa, Encoding.UTF8);

        }
    }
}

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#移动无标题窗体发布时间:2022-07-10
下一篇:
c#动态创建存储过程中,提示'go'附近有语法错误解决方案发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap