C# 关于使用JavaScriptSerializer 序列化与返序列化的操作
//开始解析 关于使用JavaScriptSerializer 序列化与返序列化的操作
//引用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | using System.Web.Script.Serialization; JavaScriptSerializer js = new JavaScriptSerializer(); Dictionary< string , Object> oList = js.DeserializeObject( "Json字符串" ) as Dictionary< string , Object>; if (oList != null ) { string strRet = "" ; if (oList.ContainsKey( "ret" )) { strRet = oList[ "ret" ].ToString(); } if (strRet == "0" ) { Dictionary< string , object > oDataList = oList[ "data" ] as Dictionary< string , Object>; object [] oItem_listData = oDataList[ "item_list" ] as object []; if (oItem_listData != null ) { System.Linq.IOrderedEnumerable< object > q = from a in oItem_listData orderby ((Dictionary< string , object >)a)[ "字段" ].ToString() descending select a; //排序的 foreach ( var oObj in q) { Dictionary< string , object > oCountriesDataList = oObj as Dictionary< string , object >; //匹配到Json串的内容 同过实体依次赋值 if (oCountriesDataList .ContainsKey( "类型" )) { 类型= oCountriesDataList [ "类型" ].ToString(); } if (oCountriesDataList .ContainsKey( "内容" )) { 内容= oCountriesDataList [ "内容" ].ToString(); } //如果 内容里面 还有下一级别的话 则继续往下面解析 Json object [] DateList = oCountriesDataList [ "内容" ] as object []; if (DateList != null ) { System.Linq.IOrderedEnumerable< object > qp = from a in DateList orderby ((Dictionary< string , object >)a)[ "时间" ].ToString() ascending select a; //时间排序 foreach ( var oObj1 in qp) { Dictionary< string , object > LowesDataList = oObj1 as Dictionary< string , object >; //数据集合 //得到里面 对用的 内容 DateTime Date = DateTime.Parse(LowesDataList [ "时间" ].ToString()); //日期 //你的类 继续赋值 add } } } } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)