Hi,
I’ve run into a strange error with my app. It runs fine in the simulator, and on an iPhone 4s. I tried it out on a real android device for the first time today and it crashed. I’m almost sure this has to do with the placement of my JSON file within the file structure.
What I’m trying to do is write a JSON file pulled in from the web to the temp directory, and then turn it into a lua table. Here is the code:
local function networkListener( event )
print ("in network listener")
if ( event.isError ) then
print ( "Network error - download failed" )
else
base = system.TemporaryDirectory
filename = "hello.json"
-- create a file path for corona i/o
local path = system.pathForFile( filename, base )
print ("The path is: " .. filename)
-- 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 file then
-- read all contents of file into a string
contents = file:read( "\*a" )
io.close( file ) -- close the file after using it
end
print("before json decode")
local t = json.decode(contents)
print("after json decode")
Here is my output from the phone:
01-29 16:20:43.372 18391 18401 I Corona : in network listener
01-29 16:20:43.372 18391 18401 I Corona : The path is: /data/data/com.mypp/cache/hello.json
01-29 16:20:43.372 18391 18401 I Corona : before json decode
01-29 16:20:43.372 18391 18401 I Corona : Lua Runtime Error: lua_pcall failed with status: 2, error message is: Invalid input: '?
I’m not sure, but I think maybe that data/data/ directory is suspect.
Any ideas? [import]uid: 112807 topic_id: 21111 reply_id: 321111[/import]