hi, I have to save a file in the system.DocumentsDirectory of my app. This file contains a single word, either "yes" or "no". Currently I'm using a .txt file. Is this OK? Or should I use a json file? Thanks.
text file vs. json file
Oct 06 2018 09:16 PM
Best Answer Rob Miracle , 07 October 2018 - 09:16 AM
Just a couple of things to think about.
1. JSON saved to a file is plain old text file. JSON is just a standard or easily saving multiple data values.
2. If don't use JSON, you have to parse your own file and turn it into your own data. Parsing can be a challenging task vs. simply using json.encode() and json.decode() to parse the data and save it into or from a Lua table for you.
3. If you have one data item, JSON is kind of pointless because if you just have "yes" or "no" and it's the only thing in the file, you won't need to do any parsing on it. Simply load it into a string and test against it.
Now the moment you need to save more than one item or if you're using a table of information, you should use JSON for your own sanity.