C# json反序列化 对象中嵌套数组 (转载)
看图:

这里可以看到是二层嵌套!!使用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
C# json反序列化 对象中嵌套数组 (转载)的更多相关文章
- C# json反序列化 对象中嵌套数组 (转载) 可能会导致循环或多重级联路径。请指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束。
C# json反序列化 对象中嵌套数组 (转载) 看图: 这里可以看到是二层嵌套!!使用C#如何实现?? 思路:使用list集合实现 → 建立类 → list集合 → 微软的 Newtonso ...
- struts2:遍历自定义字符串数组,遍历Action实例所引用对象中的数组
在struts2:OGNL表达式,遍历List.Map集合:投影的使用一文中已经讲述了OGNL遍历List.Map集合等功能. 本文简单写一个遍历数组的示范程序. 1. 遍历自定义字符串数组 < ...
- 如何向java后台的对象中传数组
1.后台对象的参数需要是是list对象 /* * copyright : GLOBALROAM Ptd Ltd * VmCreateInfo.java * Author: * zhangpengyan ...
- json反序列化对象
这个是同事研究的wcf中中根据type类型反序列化json的示例 /// <summary> /// json转对象 /// </summary> /// <param ...
- 使用jQuery+huandlebars遍历展示对象中的数组
兼容ie8(很实用,复制过来,仅供技术参考,更详细内容请看源地址:http://www.cnblogs.com/iyangyuan/archive/2013/12/12/3471227.html) & ...
- PHP将json或对象转成数组
今天老大突然给了我一个小任务,给我一个txt文件,里边是很多的json字串,要求将这些字串转换成php中的数组: 于是开足火力,用了将进5分钟的时间完成了任务,代码如下: $jsonStr = fil ...
- C# json对象中包含数组对象时,如何存入数据库
前端创建的的对象例如: C#端这样将数组提取出来存入
- 向json对象中添加数组
// JSONArray jsonArray = new JSONArray();// for (int i = 0; i < list.size(); i++) {// JSONObject ...
- eval()解析json以及js中js数组、对象与json之间的转换
http://www.cnblogs.com/myjavawork/articles/1979279.html https://www.cnblogs.com/coder-economy/p/6203 ...
随机推荐
- ABP框架系列之三十:(Javascript-API-Javascript-API)
ASP.NET Boilerplate provides a set of objects and functions that are used to make javascript develop ...
- CentOS No manual entry for man 没有 xx 的手册页条目
yum install -y man man-pages man-pages-overrides https://unix.stackexchange.com/questions/182500/no- ...
- 算法入门:最大子序列和的四种算法(Java)
最近再学习算法和数据结构,推荐一本书:Data structures and Algorithm analysis in Java 3rd 以下的四种算法出自本书 四种最大子序列和的算法: 问题描述 ...
- ElasticSearch权威指南学习(排序)
排序方式 相关性排序 默认情况下,结果集会按照相关性进行排序 -- 相关性越高,排名越靠前. 相关性分值会用_score字段来给出一个浮点型的数值,所以默认情况下,结果集以_score进行倒序排列. ...
- iptables概述
[参考文章]:iptables详解-朱双印个人日志 [参考文章]:linux iptables详解--个人笔记 [参考文章]:iptables详解--转 [参考文章]:linux下IPTABLES配置 ...
- ubuntu 16.04下使用 python pip的安装问题。
ubuntu 16.04使用 pip安装软件时,不知道为什么不能使用sudo pip install XXX 需要使用的是:python -m pip install XXX才可以.
- Linux中vim文本编辑器的介绍和使用方法
vim主要模式介绍,vim命令模式. 确保系统已经安装了VIM工具 [root@panda ~]# rpm -qf `which vim` [root@panda ~]# rpm -qf `which ...
- fast.ai(零)windows + pytorch 0.4
一.下载 git clone https://github.com/fastai/fastai.git 或者直接下载下来 二.安装pytorch 去官网安装建议安装即可 https://pytorch ...
- 一站式SpringBoot for NoSQL Study Tutorial 开发教程学习手册
SpringBoot2.0 + NoSQL使用教程,项目名称:“SpringBoot2NoSQL” 项目地址: https://gitee.com/475660/SpringBoot2NoSQL 项目 ...
- ubuntu下截图工具推荐 -- [deepin-scrot]
有时候我们需要在linux下截图来保存.如果你仅仅需要全屏截图的话其实可以直接按键盘上的PrScrn或者Press Print键盘按键来实现即可: 但是如果你需要对截图的图片进行标记.画个线画个圈加个 ...