2012-06-04 20 views
2

我有在下面的toJSON()方法返回一個字符串,它僅僅是一個問題「{}」JsonConvert系列化回報「{}」

public class GenericRequest 
      { 
       public enum SupportedCommands 
       { 
        REGISTER, LOGIN, LOGOUT 
       } 

       private SupportedCommands command; 
       private String authentication; 
       private String password; 
       private String email; 

       public GenericRequest(SupportedCommands comm, string aut, string pass, string mail) 
       { 
        command = comm; 
        authentication = aut; 
        password = pass; 
        email = mail; 
       } 

       virtual public string ToJson() 
       { 
        return JsonConvert.SerializeObject(this); 
       } 
    } 

有任何想法爲什麼系列化命令沒有按序列化班級的成員?

回答

5

該字段是私人的;嘗試使用公共屬性(或將公共屬性中的字段封裝)。

+0

非常感謝你! –