JSON does not serialize fields - it only serialises properties, so
MemberSerialization.OptIn
will make no difference.
Change your class:
public class Class1
{
public bool flag { get; set; }
public bool flag2 { get; set; }
public Class1()
{
flag = false;
flag2 = false;
}
}
And discard the attribute - you'll get a slightly better result (but not much better, since you always serialize a new Class1 Instance so it will always save
false
values: you need to serialize the instance inside your Form, not outside it).