local cjson = require("cjson") local xpcall = xpcall -- 设置 处理稀疏数组 -- https://www.kyne.com.au/~mark/software/lua-cjson-manual.html#encode_sparse_array cjson.encode_sparse_array(true, 1, 1) -- https://github.com/cloudwu/lua-cjson/pull/8 cjson.encode_empty_table_as_array("on") -- https://github.com/cloudwu/lua-cjson/pull/10 cjson.encode_number_precision(16) local json = {} function json.encode(var) local function _logExce(err) print("json encode", err) end local status, result = xpcall(cjson.encode, _logExce, var) if status then return result end end function json.decode(text) if not text then return end local function _logExce(err) print("json decode", text, err) end local status, result = xpcall(cjson.decode, _logExce, text) if status then return result end end return json