我使用JSON.NET将类对象序列化为.txt文件:
public static void SaveDataToFile<T>(T data, string directory)
{
JsonSerializerSettings settings = new JsonSerializerSettings {NullValueHandling = NullValueHandling.Ignore, TypeNameHandling = TypeNameHandling.All };
//Save as JSON string to file
System.IO.File.WriteAllText(directory, JsonConvert.SerializeObject(data, typeof(T), settings));
}
但是.txt文件里面有空/无数据(在Notepad ++中查看):
什么会使序列化对象有这样的数据?