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


    //开始解析 关于使用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
    
    }
    }
    }
    }
    

      

  • 相关阅读:
    解决英文版Windows中软件乱码问题
    退出程序时进行确认提醒
    Dreamweaver插件,FireFox插件名称集合
    网页炸弹根本就不算技术
    虚拟格式化硬盘
    当前上下文中不存在名称“Server”的原因
    ASP脚本在Webshell下的安全解决方案
    ASP.NET关于http/1.1 500 Server Error 的解决办法
    在网页文件中插入QQ强制聊天
    删除visual studio最近打开的项目列表
  • 原文地址:https://www.cnblogs.com/goodluckily/p/11027475.html
Copyright © 2020-2023  润新知