JSON writing to a file.

local jsonString = json.encode(tableToEncode) function saveToFile(path, data) local filepath = system.pathForFile( path, system.DocumentsDirectory ) local file = io.open( filepath, "w" ) file:write(data) io.close( file ) file = nil end saveToFile("map.json", jsonString)

Above is the code that I have written in order to write the json data to a file.

I have tried printing to see if the file is being written. Corona says that it is being written.

The only things I can think of are that it is being written to the wrong directory, or I’m doing something just completely wrong.

Any information would be appreciated :smiley:

And your question is?

Sorry. It’s not writing a file at all. Any possible reasons you can think of that might be causing that?

‘Not writing’ - where did you check?

the project directory. where is the default write location?

Edit: and how do I change it?

When Corona simulates write/read operations (on mac or pc) it creates special folder for storing files for each project on your drive. This folder is called sandbox. To find this folder click in Corona simulator ‘file’ and then ‘show sandbox folder’. There will be two folders - one for temporary files and second for persistent documents. System.documentsDirectory is second one.

Okay, so it is writing. I’ve got it working; however, I cannot find this “sandbox” folder you’re talking about. I’ve searched my entire computer for sandbox and nothing came up aside from garrysmod stuff.

Please be a little more specific on the file path. I’m using Windows 7.

I have written in post above - read again.

Yes…I read that. What exactly is the " Corona Simulator ‘file’"? and where is the “show sandbox folder” button?

Edit: Scratch that - There is no “show sandbox folder” button under File in my simulator

Just see menu bar in corona simulator.

okay so it’s in %appdata%. thanks.

And your question is?

Sorry. It’s not writing a file at all. Any possible reasons you can think of that might be causing that?

‘Not writing’ - where did you check?

the project directory. where is the default write location?

Edit: and how do I change it?

When Corona simulates write/read operations (on mac or pc) it creates special folder for storing files for each project on your drive. This folder is called sandbox. To find this folder click in Corona simulator ‘file’ and then ‘show sandbox folder’. There will be two folders - one for temporary files and second for persistent documents. System.documentsDirectory is second one.

Okay, so it is writing. I’ve got it working; however, I cannot find this “sandbox” folder you’re talking about. I’ve searched my entire computer for sandbox and nothing came up aside from garrysmod stuff.

Please be a little more specific on the file path. I’m using Windows 7.

I have written in post above - read again.

Yes…I read that. What exactly is the " Corona Simulator ‘file’"? and where is the “show sandbox folder” button?

Edit: Scratch that - There is no “show sandbox folder” button under File in my simulator

Just see menu bar in corona simulator.