C# json反序列化 对象中嵌套数组 (转载)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了C# json反序列化 对象中嵌套数组 (转载),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2304字,纯文字阅读大概需要4分钟。
内容图文
看图:
这里可以看到是二层嵌套!!使用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); } } }
来源:https://www.cnblogs.com/panmy/p/5924324.html
原文:https://www.cnblogs.com/hao-1234-1234/p/8667373.html
内容总结
以上是互联网集市为您收集整理的C# json反序列化 对象中嵌套数组 (转载)全部内容,希望文章能够帮你解决C# json反序列化 对象中嵌套数组 (转载)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。