Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | GarlicPerson |
Hello!
I’ve got a question and would appreciate the help. My game uses an external JSON file to store certain key-value pairs that the game must remember between runs. In the initial file, i store the data one key-value pair per line. Like this:
{“key1” : “value1”,
“key2”:“value2”,
“key3”,“value3”}
I can read and parse the file using:
var file = File.new()
file.open(filepath, file.READ)
var json=file.get_as_text()
var json_result = JSON.parse(json).result
file.close()
However when i write it back using:
file.open(filepath, File.WRITE)
file.store_line(to_json(json_result))
file.close()
The resulting file will look like this:
{“key1”:“value1”,“key2”:“value2”,“key3”,“value3”}
Which works and parsable again… but simply hurts my eyes to look at if it will have more records.
And if I use this to write it back:
file.open(filepath, File.WRITE)
file.store_var(json_result)
file.close()
Then I the file will look something like:
NULNULNUL Key1 NUL NULL Value1 NUL.
NULNUL Key2 NULNUL Value2 NUL NUL
Is there a way to get back the original file structure?
Thanks in advance folks!
https://www.youtube.com/watch?v=g_7hgbxjtLY
Landroval | 2023-02-12 16:26