Json 解析无法在设备上运行,而在模拟器上运行完美,在我读取或写入一些数据的地方无法打开该场景。我为 Json 解析做了一个类 这里是,
module(..., package.seeall)
local json=require ("json")
function saveTable(t,filename)
local path = system.pathForFile(filename, system.DocumentsDirectory)
local file = io.open(path,"w")
if file then
local contents = json.encode(t)
file:write(contents)
io.close(file)
return true
else
return false
end
end
function loadTable(filename)
local path = system.pathForFile(filename, system.DocumentsDirectory)
local contents = ""
local myTable = {}
local file = io.open(path,"r")
if file then
local contents = file:read("*a")
myTable = json.decode(contents)
io.close(file)
return myTable
end
return nil
end
我实际上想要在 Corona 上替代 NSUserDefaults。有什么帮助吗?