private static void serializeObject(MySaveObject obj) { Stream stream = File.Open(file, FileMode.Create); BinaryFormatter bformatter = new BinaryFormatter(); //write obj to file bformatter.Serialize(stream, obj); stream.Close(); }
private static void start() { //serialize the obj MySaveObject obj = new MySaveObject(); obj.jsonString = "{'name':'tom'}"; serializeObject(obj); //deserialize and read back the obj that has the saved data MySaveObject objNew = deserializeObject(); Console.WriteLine(objNew.jsonString); //another step if want //read the saved data and convert the saved jsonString from obj into entity Entity obj2 = JsonConvert.DeserializeObject<Entity>(obj.jsonString); Console.WriteLine(obj2.name); }