源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 regels
846 B

4 weken geleden
  1. function table2json(t)
  2. local function serialize(tbl)
  3. local tmp = {}
  4. for k, v in pairs(tbl) do
  5. local k_type = type(k)
  6. local v_type = type(v)
  7. local key = (k_type == "string" and "\"" .. k .. "\":")
  8. or (k_type == "number" and "")
  9. local value = (v_type == "table" and serialize(v))
  10. or (v_type == "boolean" and tostring(v))
  11. or (v_type == "string" and "\"" .. v .. "\"")
  12. or (v_type == "number" and v)
  13. tmp[#tmp + 1] = key and value and tostring(key) .. tostring(value) or nil
  14. end
  15. if table.maxn(tbl) == 0 then
  16. return "{" .. table.concat(tmp, ",") .. "}"
  17. else
  18. return "[" .. table.concat(tmp, ",") .. "]"
  19. end
  20. end
  21. return serialize(t)
  22. end