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 = "";
testinfo.Count = ""; List<sonXMText> listSonText = new List<sonXMText>();
sonXMText sontext1 = new sonXMText();
sontext1.xmleixing = "市重点交通";
sontext1.xmtype = "";
sontext1.count = "";
sontext1.url = "../ProjectManage/Pagesilding/ZongHeJiaoTong/Zonghetra/Zonghetra_List.aspx?xmtype=0101";
sontext1.progress = "52.61";
sontext1.WaitCount = ""; sonXMText sontext2 = new sonXMText();
sontext1.xmleixing = "支路网建设";
sontext1.xmtype = "";
sontext1.count = "";
sontext1.url = "../ProjectManage/Pagesilding/ZongHeJiaoTong/Zonghetra/Zonghetra_List.aspx?xmtype=0101";
sontext1.progress = "52.61";
sontext1.WaitCount = ""; 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); }
}
}
C# 对json对象嵌套数组的更多相关文章
- json对象,数组,字符串总结
关于json对象,数组,字符串的总结 什么是json? JSON(JavaScript Object Notation) 一种轻量级的数据交换格式,JSON采用完全独立于语言的文本格式...(来自百 ...
- ASP.NET MVC Controller接收ajax post方式发送过来的json对象或数组数据
本例旨在说明我的一种Controller接收ajax提交(POST)过来的json对象或数组信息的方式,感觉应该有更好的方式,欢迎提出宝贵意见. JSON.stringify(jsonObj)不支持I ...
- js处理复杂数据格式数组嵌套对象,对象嵌套数组,reduce处理数据格式
let list=[ {id:1,name:'a'}, {id:1,name:'b'}, {id:1,name:'c'}, {id:2,name:'A'}, {id:2,name:'B'}, {id: ...
- json字符串、json对象、数组 三者之间的转换
json字符串转化成json对象 // jquery的方法 var jsonObj = $.parseJSON(jsonStr) //js 的方法 var jsonObj = JSON.parse(j ...
- json字符串、json对象、数组之间的转换
json字符串转化成json对象 // jquery的方法 var jsonObj = $.parseJSON(jsonStr) //js 的方法 var jsonObj = JSON.parse(j ...
- Java对象与JSON互相转换jsonlib以及手动创建JSON对象与数组——(二)
首先声明一下,jsonlib转换与GSON相比太差劲了,操作不是一般的繁琐.GSON可以直接转换成各种集合与对象类型.强烈推荐使用GSON.而且GSON一个方法就可以解决,jsonlib转来转去太繁琐 ...
- JSON数组,JSON对象,数组的区别与基本操作整理
JSON 语法规则 JSON 语法是 javascript 对象表示语法的子集. 数据在名称/值对中 数据由逗号分隔 花括号保存对象 方括号保存数组 JSON 名称/值对 JSON 数据的书写格式是: ...
- json对象和数组
Json数据就是格式化的字符串.c#中如果做为参数调用,类型就是string.1.Json数组 方括号[{ "firstName":"John" , " ...
- js json对象和数组对象
动态添加json对象: var json = {}; json['a'] = 'a'; 动态添加数组对象: var arr = []; arr['a'] = 'a';
随机推荐
- Python开发【模块】:Concurrent
concurrent 模块 回顾: 对于python来说,作为解释型语言,Python的解释器必须做到既安全又高效.我们都知道多线程编程会遇到的问题,解释器要留意的是避免在不同的线程操作内部共享的数据 ...
- Python将科学计数法数值转换为指定精度浮点数
Python将科学计数法数值转换为指定精度浮点数 In [20]:money = 1190000.0 In [21]: traded_maket_value = 13824000000 In [22] ...
- spring boot开启事务管理,使用事务的回滚机制,使两条插入语句一致
spring boot 事务管理,使用事务的回滚机制 1:配置事务管理 在springboot 启动类中添加 @EnableTransactionManagement //开启事务管理 @Enable ...
- mysql主从复制,及扩展
一.MySQL简单复制相关概念: 1. mysql复制的意义:Mysql复制是使得mysql完成高性能应用的前提 2. mysql复制的机制: SLAVE端线程: IO thread: 向主服务请求二 ...
- 手把手教你学node.js之一个简单的express应用
一个简单的express应用 目标 建立一个 lesson1 项目,在其中编写代码.当在浏览器中访问 http://localhost:3000/ 时,输出 Hello World. 挑战 访问 ht ...
- Linux笔记 #05# 断开远程连接后保持程序运行
教程:Linux 技巧:让进程在后台可靠运行的几种方法 网上搜索了一下,方法很多,选用最流行的 screen 命令参考:http://man.linuxde.net/screen 1. 安装 root ...
- ZLYD团队第一周项目总结
ZLYD团队第一周项目总结 团队项目 项目内容:我们打算利用Applet实现一个吃豆子游戏,团队初步设定游戏规则如下: 按空格键,游戏开始: 通过方向键控制吃豆者的运动方向,直到吃光所有金豆子: 吃到 ...
- How to install tensorflow on ubuntu 18.04 64bit
Ans:pip install tensorflow (note: version number of pip and python must be consistent)
- CentOS7.2 安装zookeeper3.4.9
Zookeeper-3.4.9 下载Zookeeper-3.4.9 在/usr/local下创建hadoop文件夹 将下载的文件迁移到该文件夹下,并解压 tar -zxvf zookeeper-3.4 ...
- 采用注解方式实现security
采用注解方式使用security,首先我们需要用注解方式实现Spring MVC,新建一个Maven项目 本项目目录结构如下: 我们会发现在WEB-INF中没有web.xml文件,下面会介绍,采用j ...