• JavaScriptSerializer序列化与反序列化备忘


    msdn:JavaScriptSerializer 类

    序列化:

     JavaScriptSerializer json = new JavaScriptSerializer();           
                sproduct.Text = json.Serialize(new { province = d_province, city = d_city, district = d_district });
                sproduct.Transit = json.Serialize(new { isseller = TransitText, express = express, post = post, ems = ems });

    反序列化:

    View Code
    public ActionResult EditProduct(string Id)
            {
                var p = mp.SysProducts;                       
                JavaScriptSerializer javaSerializer = new JavaScriptSerializer();
                ///解析分销城市
                var  distributionCity = javaSerializer.Deserialize<DistributionCity>(p.DistributionText);          
                ///解析运费设置
                var postageSets = javaSerializer.Deserialize<PostageSet>(p.Transit);
    
                     return View(p);
            }
            /// <summary>
            /// 分销城市 {"province":"福建","city":"厦门","district":"请选择区县"}
            /// </summary>
            public class DistributionCity
            {
                public string Province { get; set; }
                public string City { get; set; }
                public string District { get; set; }
            }
            /// <summary>
            /// 邮费设置 {isseller:bool,express:0.00,post:0.00,ems:0.00}
            /// </summary>
            public class PostageSet
            {
                public bool Isseller { get; set; }
                public decimal Express { get; set; }
                public decimal Post { get; set; }
                public decimal Ems { get; set; }
            }
  • 相关阅读:
    Java统计程序运行时间(转)
    有符号定点数的表示方法
    移位运算符
    索引
    self与super的区别(转)
    Java经典题型(未完成)
    ObjectiveC 的 self 和 super 详解
    边界计算与不对称边界
    各种排序总结
    运算符的优先级
  • 原文地址:https://www.cnblogs.com/aaronguo/p/2861244.html
Copyright © 2020-2023  润新知