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

}
}
}
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM