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.
I don’t see why not. Keep coding don’t worry.
Just a couple of things to think about.
-
JSON saved to a file is plain old text file. JSON is just a standard or easily saving multiple data values.
-
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.
-
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.
Rob
got it, thanks.
I don’t see why not. Keep coding don’t worry.
Just a couple of things to think about.
-
JSON saved to a file is plain old text file. JSON is just a standard or easily saving multiple data values.
-
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.
-
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.
Rob
got it, thanks.