序列化:
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; } }