前台我们一般用ajax来发送数据到后端进行处理,如果json数据结构和后台的实体类结构一致,就直接可以反序列化为指定的对象进行操作,非常方便。

前端发送的json数据结构:


后端实体结构:

    public partial class Cures
    {
        public string CureID { get; set; }
        public string MainCureSubjectID { get; set; }
        public string MainCureSubjectName { get; set; }
        public string PatientID { get; set; }
        public string Symptom { get; set; }
        public string Diagnosis { get; set; }
        public string CompareID { get; set; }
        public string Therapy { get; set; }
        public string Draft { get; set; }
        public Nullable<System.DateTime> CureDate { get; set; }
        public Nullable<int> PrescriptionDosage { get; set; }
        public Nullable<decimal> Amount { get; set; }
        public string CureDocPath { get; set; }
        public Nullable<int> CureType { get; set; }
        public string Remark { get; set; }
    }

我这个是partial分部类,还有一些参数,保证json的参数在对应实体类里都有,就可以进行反序列化了。

Cures cure = Deserialize<Cures>(CureInfo);
CureInfo为接收到的json字符串,Deserialize是反序列化,如果是json数组,那么就反序列化为集合Deserialize<List<T>>了。



Logo

新一代开源开发者平台 GitCode,通过集成代码托管服务、代码仓库以及可信赖的开源组件库,让开发者可以在云端进行代码托管和开发。旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐