魔改json库,最后套一层pcall防止致命错误
This commit is contained in:
@@ -300,7 +300,9 @@ do--json
|
||||
error("unexpected type '" .. t .. "'")
|
||||
end
|
||||
|
||||
function json.encode(val) return encode(val) end
|
||||
function json.encode(val)
|
||||
return pcall(encode,val)
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Decode
|
||||
@@ -516,7 +518,7 @@ do--json
|
||||
decode_error(str, idx, "unexpected character '" .. chr .. "'")
|
||||
end
|
||||
|
||||
function json.decode(str)
|
||||
local function decode(str)
|
||||
if type(str) ~= "string" then
|
||||
error("expected argument of type string, got " .. type(str))
|
||||
end
|
||||
@@ -525,6 +527,9 @@ do--json
|
||||
if idx <= #str then decode_error(str, idx, "trailing garbage") end
|
||||
return res
|
||||
end
|
||||
function json.decode(str)
|
||||
return pcall(decode,str)
|
||||
end
|
||||
end
|
||||
function copyList(org)
|
||||
local L={}
|
||||
|
||||
Reference in New Issue
Block a user