DP-S-Script/Dps_A/BaseClass/JsonClass/Json.nut

30 lines
687 B
Plaintext

//Json类
class Json {
//Table 转 String
function Encode(Table) {
return JSONEncoder.encode(Table);
}
function OldDecode(Str) {
Str = sq_DecondeJson(Str);
local NewStr = "local _M = " + Str + ";\n return _M;\n";
local Func = compilestring(NewStr);
try {
local Obj = Func();
if (typeof(Obj) == "table" || typeof(Obj) == "array") {
if (Obj.len() > 0) return Obj;
}
} catch (exception) {
}
error("错误的包内容: " + NewStr);
return null;
}
//String 转 Table
function Decode(Str) {
return JSONParser.parse(Str);
}
}