zoukankan      html  css  js  c++  java
  • Nhibernate对象转JSON

    在需要转JSON的对象类头中加入

     [DataContract(IsReference = true)]  属性

    在类中的每个属性都添加

    [JsonProperty]

    属性

     1   [DataContract(IsReference = true)]
     2     public class Project
     3     {
     4         [JsonProperty]
     5         public virtual int id
     6         {
     7             get;
     8             set;
     9         }
    10         [JsonProperty]
    11         public virtual string name
    12         {
    13             get;
    14             set;
    15         }
    16         [JsonProperty]
    17         public virtual int payScore
    18         {
    19             get;
    20             set;
    21         }
    22         [JsonProperty]
    23         public virtual int score
    24         {
    25             get;
    26             set;
    27         }
    28         [JsonProperty]
    29         public virtual int userID
    30         {
    31             get;
    32             set;
    33         }
    34 
    35         [JsonProperty]
    36         public virtual ISet<Aduit> Aduits
    37         {
    38             get;
    39             set;
    40         }
    41        // public virtual List<SingleForm> singleFormList
    42     }

    再取出JSON时

    1             var result = projectManager.MyProject(id);
    2             JsonSerializerSettings settings = new JsonSerializerSettings();
    3             settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
    4             string s = JsonConvert.SerializeObject(result, settings); 
    5             return s;  
  • 相关阅读:
    git整理
    oracle中utl_raw
    mysqltest语法整理
    oracle存储过程中拼接字符串及转义逗号
    oracle存储过程中循环游标,变量的引用
    oracle触发器
    oracle序列相关
    编译1
    面向对象的脚本语言的类的实现
    词法分析器
  • 原文地址:https://www.cnblogs.com/cwmizlp/p/9482945.html
Copyright © 2011-2022 走看看