C # nested Number Groups in json deserialization objects,

Source: Internet
Author: User

C # nested Number Groups (reproduced) in json deserialization objects ),
 

Figure:


Here we can see that it is a layer-2 nested !! How to Implement C ??

Idea: Use list set implementation → create class → list set → Microsoft Newtonsoft. Json (an open-source Json serialization and deserialization in. NET)

SonXMText class

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 class

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 = "Integrated traffic";
            testinfo.XMTYPE = "01";
            testinfo.Count = "108";

            List<sonXMText> listSonText = new List<sonXMText>();
            sonXMText sontext1 = new sonXMText();
            Sontext1.xmleixing = "City focus traffic";
            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 = "Bridge network construction";
            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);

        }
    }
} 

 

Source: https://www.cnblogs.com/panmy/p/5924324.html

 

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.