summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/settings.json15
-rw-r--r--server/src/json/encode.lua14
2 files changed, 14 insertions, 15 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 99940caf..db5132b3 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,10 +1,9 @@
{
- "Lua.diagnostics.globals" : [
- "TEST",
- "ERR",
- "OUT",
- "IN",
- "log",
- "ac"
- ]
+ "Lua.diagnostics.globals": [
+ "ERR",
+ "OUT",
+ "IN",
+ "log",
+ "ac"
+ ]
}
diff --git a/server/src/json/encode.lua b/server/src/json/encode.lua
index 4bba26de..93d0b954 100644
--- a/server/src/json/encode.lua
+++ b/server/src/json/encode.lua
@@ -27,14 +27,14 @@ local esc_map = {
local function encode(data, key)
n = n + 1
if not tabs[n] then
- tabs[n] = rep('\t', n)
+ tabs[n] = rep(' ', n)
end
local tp = type(data)
if tp == 'table' then
if not data[1] and next(data) then
-- 认为这个是哈希表
if key then
- index=index+1;lines[index] = tabs[n] .. '"' .. gsub(key, '[\\\r\n\t"]', esc_map) .. '" : {\n'
+ index=index+1;lines[index] = tabs[n] .. '"' .. gsub(key, '[\\\r\n\t"]', esc_map) .. '": {\n'
else
index=index+1;lines[index] = tabs[n] .. '{\n'
end
@@ -69,7 +69,7 @@ local function encode(data, key)
else
-- 认为这个是数组
if key then
- index=index+1;lines[index] = tabs[n] .. '"' .. gsub(key, '[\\\r\n\t"]', esc_map) .. '" : [\n'
+ index=index+1;lines[index] = tabs[n] .. '"' .. gsub(key, '[\\\r\n\t"]', esc_map) .. '": [\n'
else
index=index+1;lines[index] = tabs[n] .. '[\n'
end
@@ -92,26 +92,26 @@ local function encode(data, key)
data = '0'
end
if key then
- index=index+1;lines[index] = tabs[n] .. '"' .. gsub(key, '[\\\r\n\t"]', esc_map) .. '" : ' .. data
+ index=index+1;lines[index] = tabs[n] .. '"' .. gsub(key, '[\\\r\n\t"]', esc_map) .. '": ' .. data
else
index=index+1;lines[index] = tabs[n] .. data
end
elseif tp == 'boolean' then
if key then
- index=index+1;lines[index] = tabs[n] .. '"' .. gsub(key, '[\\\r\n\t"]', esc_map) .. '" : ' .. tostring(data)
+ index=index+1;lines[index] = tabs[n] .. '"' .. gsub(key, '[\\\r\n\t"]', esc_map) .. '": ' .. tostring(data)
else
index=index+1;lines[index] = tabs[n] .. tostring(data)
end
elseif tp == 'nil' then
if key then
- index=index+1;lines[index] = tabs[n] .. '"' .. gsub(key, '[\\\r\n\t"]', esc_map) .. '" : null'
+ index=index+1;lines[index] = tabs[n] .. '"' .. gsub(key, '[\\\r\n\t"]', esc_map) .. '": null'
else
index=index+1;lines[index] = tabs[n] .. 'null'
end
elseif tp == 'string' then
local str = gsub(data, '[\\\r\n\t"]', esc_map)
if key then
- index=index+1;lines[index] = tabs[n] .. '"' .. gsub(key, '[\\\r\n\t"]', esc_map) .. '" : "' .. str .. '"'
+ index=index+1;lines[index] = tabs[n] .. '"' .. gsub(key, '[\\\r\n\t"]', esc_map) .. '": "' .. str .. '"'
else
index=index+1;lines[index] = tabs[n] .. '"' .. str .. '"'
end