I would ALWAYS check the documents directory, but have a test in the load file function which defaults to the resource directory if nothing is found in the documents directory, and saves a copy in the docs directory for future use. This way it will use your default file if nothing is found in the documents directory.
This is my load file function:
loadFile = function( filename, base ) -- set default base dir to DocumentsDirectory if none specified if not base then base = system.DocumentsDirectory; end -- create a file path for corona i/o local path = system.pathForFile( filename, base ) -- will hold contents of file local contents -- io.open opens a file at path. returns nil if no file found local file = io.open( path, "r" ) --if the file exists then read all contents of file into a string if file then contents = file:read( "\*a" ) io.close( file ) -- close the file after using it else --read from resource directory instead... print("defaulting to ResourceDirectory") jsonDefaulted = true local path = system.pathForFile( filename, system.ResourceDirectory ) local file = io.open(path, "r") if file then contents = file:read( "\*a" ) io.close (file) end --...then save the file to DocumentsDirectory for future use local savePath = system.pathForFile(fileName, system.DocumentsDirectory ) local saveFile = io.open(savePath, "w") saveFile:write(contents) io.close(saveFile) print("Saved "..fileName.." to DocumentsDirectory") end return contents end
Another thing to mention is that sometimes the user may not have an internet connection, so you’ll need to account for that too (loading the default file should be fine though, depending on what your app does).
Also it may be wise to delay going to your game scene or whichever scene uses this json data until a response is received.
You could just put the goToScene in the network listener, again you’ll need to account for the user having no internet connection though.