C# 关于使用JavaScriptSerializer 序列化与返序列化的操作
Posted goodluckily
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C# 关于使用JavaScriptSerializer 序列化与返序列化的操作相关的知识,希望对你有一定的参考价值。
//开始解析
//引用
//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
以上是关于C# 关于使用JavaScriptSerializer 序列化与返序列化的操作的主要内容,如果未能解决你的问题,请参考以下文章