码迷,mamicode.com
首页 > Web开发 > 详细

asp.net mvc中如何处理字符串与对象之间的序列化与反序列化(一)

时间:2017-07-14 10:04:02      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:data-   如何   class   start   public   ret   style   info   serialize   

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

前端发送的json数据结构:

技术分享

后端实体结构:

[csharp] view plain copy
  1. public partial class Cures  
  2. {  
  3.     public string CureID { get; set; }  
  4.     public string MainCureSubjectID { get; set; }  
  5.     public string MainCureSubjectName { get; set; }  
  6.     public string PatientID { get; set; }  
  7.     public string Symptom { get; set; }  
  8.     public string Diagnosis { get; set; }  
  9.     public string CompareID { get; set; }  
  10.     public string Therapy { get; set; }  
  11.     public string Draft { get; set; }  
  12.     public Nullable<System.DateTime> CureDate { get; set; }  
  13.     public Nullable<int> PrescriptionDosage { get; set; }  
  14.     public Nullable<decimal> Amount { get; set; }  
  15.     public string CureDocPath { get; set; }  
  16.     public Nullable<int> CureType { get; set; }  
  17.     public string Remark { get; set; }  
  18. }  


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

[csharp] view plain copy
  1. Cures cure = Deserialize<Cures>(CureInfo);  

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

asp.net mvc中如何处理字符串与对象之间的序列化与反序列化(一)

标签:data-   如何   class   start   public   ret   style   info   serialize   

原文地址:http://www.cnblogs.com/gdsblog/p/7168247.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!