I have this code to save a table as JSON
function File:Save(data, filename)
if (not filename) then print('FileIO REQUIRES filename'); return 0 end
local path = system.pathForFile( filename, system.DocumentsDirectory )
local fl, errstr = io.open(path, "w" )
if fl then
local contents = json.encode(data)
fl:write(contents)
io.close(fl)
else print('ERROR SAVING FILE\>\> ' .. errstr) end
end
For some reason this code does not work. If I change to io.open(“out.json”, “w”) it ends up working fine, and I get the out.json file in my project folder on Windows. On Mac, I don’t get anything either way.
I am wondering why system.pathForFile isn’t working for io.open in this call but the function works perfectly if you hard code the filename in the io.open().
I am also wondering why I am getting inconsistent results between Windows 7 Pro x64 and Mac OS X 10.8.2. Windows I can get the function to work by using a hard coded file name rather than using the pathForFile() but on Mac that doesn’t work.
[import]uid: 160288 topic_id: 33790 reply_id: 333790[/import]