1111
This commit is contained in:
30
Dps_A/BaseClass/JsonClass/Json.nut
Normal file
30
Dps_A/BaseClass/JsonClass/Json.nut
Normal file
@@ -0,0 +1,30 @@
|
||||
//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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user