zoukankan      html  css  js  c++  java
  • C# 序列化与反序列化

    前台拼json,json 格式

    // [{}, {}, {}]

    //{ 
    // "DoctorID": "1635a62e-eaea-499d-8d12-94ecd256ebdc",
    // "DoctorName": "林心如",
    // "DepartmentID": "CC209858-04AE-45AC-A48C-B07EC36EC012",
    // "DepartmentName": "心外科",
    //}
    var jsonStr = "";
    var json = "[";
    var DepartmentID, DepartmentName, DoctorID, DoctorName;
    for (var i = 0; i < table.rows.length; i++) {
    if (i != 0) {
    var cellsInfo = table.rows[i].cells;
    for (var j = 0 ; j < cellsInfo.length; j++) {
    switch (j) {
    case 0:
    DepartmentName = cellsInfo[j].innerText;
    break;
    case 1:
    DepartmentID = cellsInfo[j].innerText;
    break;
    case 3:
    DoctorName = cellsInfo[j].innerText;
    break;
    case 4:
    DoctorID = cellsInfo[j].innerText;
    break;
    default:
    }
    }
    jsonStr = '{"DepartmentName":"' + DepartmentName + '","DepartmentID":"' + DepartmentID + '","DoctorName":"' + DoctorName + '","DoctorID":"' + DoctorID + '"}';
    json += jsonStr + ",";
    }
    }

    json = json.substring(0, json.length - 1) + "]";
    //console.log(json);
    var data = {requestJson:json};
    $.ajax({
    type: "post",
    url: '/SelectDoctor/SelectResult',
    dataType: "json",
    cache: false,
    data: data,
    error: function () { 
    },
    success: function (ret) { 
    }
    });
    });

    后台反序列化:

    public void SelectResult()
    {

    string json = Request.Form["requestJson"];

    //此方法可以直接把json反序列化成 对象的集合

    List<SelectDoctorModel> sdm= jss.Deserialize<List<SelectDoctorModel>>(json);

    }

    参考文档:

    http://www.cnblogs.com/dwfbenben/archive/2013/06/06/3122662.html

  • 相关阅读:
    戴文的Linux内核专题:08内核配置(5)
    如何在redhat下安装WineQQ
    如何在redhat下安装办公软件(openoffice)
    fqrouter让安卓手机登陆facebook成为可能
    戴文的Linux内核专题:08内核配置(4)
    如何登录Google美国服务器
    SSM框架搭建(转发)
    垃圾回收器
    数据生成时间表
    js控制邮箱跳转
  • 原文地址:https://www.cnblogs.com/wei-lai/p/5089354.html
Copyright © 2011-2022 走看看