How to save to more JSON data to a already created file?
So i followed this tutorial here: http://developer.xamarin.com/recipes/ios/general/file_system/save_documents/ and everything works fine but the only thing is that once a file is created that has JSON saved to it i want to be table to add a some more JSON data
right now i am using JSON.net to Serialize my data and saving it to a file
var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var filename = Path.Combine (documents, "Settings.txt"); File.WriteAllText(filename, "Write this text into a file!");
Just Do not know how to add more data to the already existing data
File.AppendText(filename, "Write this text into a file!");
This will append the text to the end of the file. If you need to insert text read the file as a string with File.ReadAllText, manipulate the string and overwrite the original file with the new string.
If you're looking to add update your JSON, you're going to want to load your already existing JSON into an object. Then update your object as required, new entries, updated entries etc.
Once you're ready to save again, clear the text file and re-write your new JSON from the object to the text file.
you can use File.AppendAllText
File.AppendAllText(@"c:\path\file.txt", "text content" + Environment.NewLine);
u can just pass the fileName..so,
File.AppendAllText(fileName, "text content" + Environment.NewLine);