Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

text file vs. json file
Started by d2gp Oct 06 2018 09:16 PM

3 replies to this topic

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.

 

Rob

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

d2gp

[GLOBAL: userInfoPane.html]
d2gp
  • Contributor

  • 235 posts
  • Corona SDK

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.



[TOPIC: post.html]
#2

agramonte

[GLOBAL: userInfoPane.html]
agramonte
  • Contributor

  • 811 posts
  • Corona SDK

I don't see why not. Keep coding don't worry.



[TOPIC: post.html]
#3

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,714 posts
  • Corona Staff

  Best Answer

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.

 

Rob



[TOPIC: post.html]
#4

d2gp

[GLOBAL: userInfoPane.html]
d2gp
  • Contributor

  • 235 posts
  • Corona SDK

got it, thanks.




[topic_controls]
[/topic_controls]