2

次のToJson()メソッドが「{}」のみの文字列を返すという問題があります。

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);
                }
    }

シリアル化コマンドがクラスのメンバーをシリアル化しない理由がわかりましたか?

4

1 に答える 1

5

フィールドはプライベートです。代わりにパブリックプロパティを使用してみてください(またはパブリックプロパティでフィールドをラップしてください)。

于 2012-06-04T21:54:22.143 に答える