欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

c# 序列化与反序列化

程序员文章站 2022-06-16 08:19:14
...

数组的页面传值后台接收

var JsonStr="[{\"GoodsName\":\"22\",\"Length\":2,\"Width\":2,\"Height\":2,\"Pack\":\"23\",\"Dweight\":2,\"Weight\":624,\"Numbers\":312,\"Cubage\":3.12,\"PremiumAmount\":null}]";
//后台接收值
JavaScriptSerializer  js=new JavaScriptSerializer();
List<T> list=js.Deserializer<T>(jsonStr);
 
 **js代码**
 
 var goodslist = [];
            var list = $("#table", $.CurrentNavtab).bootstrapTable("getAllData");    
            for (var i = 0; i < list.length; i++) {
 var gooDeatil = { "GoodsName": "垃圾", "Length":1, "Width": 1, "Height": 20, "Pack": "纸袋", "Dweight": 10, "Weight": 2, "Numbers": 1, "Cubage": 0.1, "PremiumAmount": 100 };                 
                goodslist.push(gooDeatil);
            };
            data["GoodsList"] = JSON.stringify(goodslist);

MVC后台传值,前台接收

后端代码

       ViewBag.AllowManualNo = loginUser.Org.AllowManualNo;
  
前端代码**加粗样式**
  @foreach (var item in ViewData["list"] as List<Winning.NQCS.DAL.DataObject.Settings.ZSKObj>)
                {
                    <tr>
                        <td>@Html.DisplayFor(p => item.FLMC)</td>
                        <td>@Html.DisplayFor(p => item.LXMC)</td>
                        <td>@Html.DisplayFor(p => item.MEMO)</td>
                        <td>@Html.ActionLink("编辑", "UpdateZSK", "ZSK", new { zskdm = item.ZSKDM.ToString() }, null)                         </td>
                    </tr>
                }

后端传json字符串(对象)

         return Json(GetRookieList);

前端接收

  var dataT = JSON.parse(datas);