I use this codes to save and load json data, but the error gives:
-- For save data: file:write(mime.b64(cipher:encrypt(json.encode(M.data), "123456789"))) -- For load data: M.data = json.decode(cipher:decrypt(mime.unb64(file:read("\*a")), "123456789"))
That error message tells me that the one of these is returning something bad that hoses up the sequence:
mime.b64
cipher:encrypt
json.encode
or that your data is bad
M.data
I would personally re-write it as this to find the point of failure:
print("------------ 1\n") print(m ~= nil, "m exists") print("------------ 2\n") for k,v in pairs(m.data) do print(k,v, "data in m") end print("------------ 3\n") local tmp = print(json.encode(M.data)) print(tmp) print("------------ 4\n") local tmp = cipher:encrypt( tmp ) print(tmp) print("------------ 5\n") local tmp = mime.b64( tmp ) print(tmp) -- By the time you get here, You'll know which line part of the code failed.
That error message tells me that the one of these is returning something bad that hoses up the sequence:
mime.b64
cipher:encrypt
json.encode
or that your data is bad
M.data
I would personally re-write it as this to find the point of failure:
print("------------ 1\n") print(m ~= nil, "m exists") print("------------ 2\n") for k,v in pairs(m.data) do print(k,v, "data in m") end print("------------ 3\n") local tmp = print(json.encode(M.data)) print(tmp) print("------------ 4\n") local tmp = cipher:encrypt( tmp ) print(tmp) print("------------ 5\n") local tmp = mime.b64( tmp ) print(tmp) -- By the time you get here, You'll know which line part of the code failed.