public static T Load(ref bool isNewCreate) { T data; if (!File.Exists(SerializeDataConst.SaveFilePathCS)) { data = new T(); isNewCreate = true; } else { var conentBytes = StdioUtil.ReadFile(SerializeDataConst.SaveFilePathCS); //conentBytes = CompressUtil.GZipDecompress(conentBytes);--解压缩 var content = Encoding.UTF8.GetString(conentBytes); data = JsonSerializer.Deserialize(content) as T; } data.AddDataList(); return(data); }
public void SingleInit() { var fileInfo = new FileInfo(filePath); if (!fileInfo.Exists) { var org_data = new Hashtable() { { "user_id", "user1" }, { "dict_user_tmp", new Hashtable() }, { "dict_user", new Hashtable() } }; data = org_data; return; } var conentBytes = StdioUtil.ReadFile(filePath); //conentBytes = CompressUtil.GZipDecompress(conentBytes);--½âѹËõ var content = Encoding.UTF8.GetString(conentBytes); data = MiniJson.JsonDecode(content) as Hashtable; }
//将文件数据转化为对象 public static T DeserializeFromFilePath <T>(string file_path) where T : Google.Protobuf.IMessage, new() { byte[] data_bytes = StdioUtil.ReadFile(file_path); return(Deserialize <T>(data_bytes)); }