-
-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NonSerialized不生效 #126
Comments
There's no built-in support for attributes in LitJson. Behavior is controlled either through a delegate or property modifier access. Example a custom exporter for a typeClasspublic class HelloWorld
{
public string ShouldNotBeInJson { get; set; }
public string Message { get; set; }
} Register Exporter delegateLitJson.JsonMapper.RegisterExporter<HelloWorld>((obj, writer) => {
writer.WriteObjectStart();
writer.WritePropertyName("Message");
writer.Write(obj.Message);
writer.WriteObjectEnd();
}); Usagevar toObject = new HelloWorld {
Message = "Hello world!",
ShouldNotBeInJson = "Hello"
};
var toJson = LitJson.JsonMapper.ToJson(toObject);
Console.WriteLine("To JSON: {0}", toJson); OutputTo JSON: {"Message":"Hello world!"} Example using access modifierClasspublic class HelloWorld
{
internal string ShouldNotBeInJson { get; set; }
public string Message { get; set; }
} Usagevar toObject = new HelloWorld {
Message = "Hello world!",
ShouldNotBeInJson = "Hello"
};
var toJson = LitJson.JsonMapper.ToJson(toObject);
Console.WriteLine("To JSON: {0}", toJson); OutputTo JSON: {"Message":"Hello world!"} |
你可以改造源码,添加[JsonIgnore]标签,来让特定的字段不被序列化:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
我想在序列化对象时,让某些成员变量不被序列化,于是使用了NonSerialized属性,但是该成员最终还是被序列化了,请问有什么好的解决方法吗
The text was updated successfully, but these errors were encountered: