码迷,mamicode.com
首页 > 编程语言 > 详细

C# 关于使用JavaScriptSerializer 序列化与返序列化的操作

时间:2019-06-15 15:34:16      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:reac   数据   ring   rabl   object   esc   system   desc   oob   

//开始解析 

//引用

//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 序列化与返序列化的操作

标签:reac   数据   ring   rabl   object   esc   system   desc   oob   

原文地址:https://www.cnblogs.com/goodluckily/p/11027475.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!