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