
C#实现Json嵌套数组文件解析为对象
������������������������������������������������������������������List��������������������������������������������������������������������������� ���������������������:Newtonsoft.json.dll���������JSON������������������������:List���������������������������
发布日期:2021-05-10 09:24:54
浏览次数:20
分类:精选文章
本文共 3401 字,大约阅读时间需要 11 分钟。
JSON���������������������������������
������������������
������������������������������������������JSON������������������������������������������������JSON������������������������������������������������������
������������������
2.1 ������������������������������������MapInfo.cs
namespace JsonDemo{ public class MapInfo { public string mapName { get; set; } public string count { get; set; } public string type { get; set; } public string url { get; set; } public string progress { get; set; } public string waitCount { get; set; } }}
2.2 ������������������������������TestInfo.cs
using System.Collections.Generic;namespace JsonDemo{ public class TestInfo { public string XMText { get; set; } public string XMTYPE { get; set; } public string XMCount { get; set; } public ListmapInfos { get; set; } }}
2.3 ������JSON���������������������������
using JsonDemo;using Kernal;using Newtonsoft.Json;using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;namespace XmlHelper{ public class Program { public static void Main(string[] args) { // ������JSON������������ string filepath = $@"e:\Zhonghejiaotong.json"; // ������JSON������ ListtestInfos = new List (); var jsonData = GetJsonFile(filepath); // ���JSON������������������������ var deserializeObject = JsonConvert.DeserializeObject947) List >(jsonData); // ������������������ foreach (var item in testInfos) { // ��������������������� Console.WriteLine($\"{item.XMText}\": {item.XMTYPE}\", {item.XMCount}"); // ������������������������������ var mapInfos = item.mapInfos; foreach (var mapInfo in mapInfos) { Console.WriteLine($"\t{mapInfo.mapName}\: {mapInfo.count}"); Console.WriteLine($"\t\t{mapInfo.type}\: {mapInfo.url}"); Console.WriteLine($"\t\t{mapInfo.progress}\: {mapInfo.waitCount}"); Console.WriteLine(); } } Console.ReadLine(); } // ��������������������������� public static string GetJsonFile(string filepath) { string json = string.Empty; using (FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) { using (StreamReader sr = new StreamReader(fs, Encoding.UTF8)) { json = sr.ReadToEnd(); } } return json; } }}
������
���������������������������������C#���������������JSON������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
能坚持,总会有不一样的收获!
[***.219.124.196]2025年04月01日 12时02分29秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
WCF WebHttp Services in .NET 4
2021-05-09
Powershell中禁止执行脚本解决办法
2021-05-09
HTTP协议状态码详解(HTTP Status Code)
2021-05-09
JMeter 中实现发送Java请求
2021-05-09
设计模式点滴
2021-05-09
数据库优化
2021-05-09
[备忘]域用户登陆出现“此工作站和主域间的信任关系失败”错误解决方法
2021-05-09
继续聊WPF——用Blend自定义Listview控件的列表头
2021-05-09
【WPF】制作自定义的列表项面板
2021-05-09
【.net 深呼吸】启动一个进程并实时获取状态信息
2021-05-09
OO_Unit2 多线程电梯总结
2021-05-09
json-lib的使用《二》
2021-05-09
LeetCode52题,别再问我N皇后问题了
2021-05-09
简单实用算法——字节位序反转
2021-05-09
webpack之带有可自动打开浏览器及热重载的基本配置
2021-05-09
前端的批量接口如何快速响应?有没有通用解决方案?
2021-05-09
Shader 入门笔记(一) 如何学习shader
2021-05-09
Huffman树及其编解码
2021-05-09
分布式、高并发、高性能场景(抢购、秒杀、抢票、限时竞答)数据一致性解决方案
2021-05-09