require("json")
result = {
["ip"]="192.168.0.177",
["date"]="2018-1-21",
} local test = assert(io.open("/tmp/abc.txt", "w"))
result = json.encode(result)
test:write(result)
test:close() require("json")
local test = io.open("/tmp/abc.txt", "r")
local readjson= test:read("*a")
local table =json.decode(readjson)
test:close()
print("ip: " .. table["ip"])
参考:
https://my.oschina.net/u/223340/blog/382895
http://lua-users.org/wiki/SaveTableToFile
https://*.com/questions/36834786/how-to-save-a-table-to-a-file-from-lua/48517263#48517263