Lua Table to Json
来源:互联网 发布:文件上传阿里云oss2 编辑:程序博客网 时间:2024/06/07 13:36
function tableTojson(t)
local function serialize(tbl)
local tmp = {}
for k, v in pairs(tbl) do
local k_type = type(k)
local v_type = type(v)
local key = (k_type == "string" and "\"" .. k .. "\":") or (k_type == "number" and "")
local value = (v_type == "table" and serialize(v))
or (v_type == "boolean" and tostring(v))
or (v_type == "string" and "\"" .. v .. "\"")
or (v_type == "number" and v)
tmp[#tmp + 1] = key and value and tostring(key) .. tostring(value) or nil
end
if table.maxn(tbl) == 0 then
return "{" .. table.concat(tmp, ",") .. "}"
else
return "[" .. table.concat(tmp, ",") .. "]"
end
end
assert(type(t) == "table")
return serialize(t)
end
local function serialize(tbl)
local tmp = {}
for k, v in pairs(tbl) do
local k_type = type(k)
local v_type = type(v)
local key = (k_type == "string" and "\"" .. k .. "\":") or (k_type == "number" and "")
local value = (v_type == "table" and serialize(v))
or (v_type == "boolean" and tostring(v))
or (v_type == "string" and "\"" .. v .. "\"")
or (v_type == "number" and v)
tmp[#tmp + 1] = key and value and tostring(key) .. tostring(value) or nil
end
if table.maxn(tbl) == 0 then
return "{" .. table.concat(tmp, ",") .. "}"
else
return "[" .. table.concat(tmp, ",") .. "]"
end
end
assert(type(t) == "table")
return serialize(t)
end
0 0
- Lua Table to Json
- lua table to string
- lua table to string,string to table
- Json生成Lua Table工具
- table to json
- Lua Save Table to File
- cocos2dx lua中table与json互转
- cocos2dx lua中table与json互转
- lua稀疏table转换为json
- JSON 与 LUA Table 相互转换
- Json和Lua table互转的Lua模块
- lua: attempt to call a table value
- lua: attempt to call a table value .
- lua中使用json:table转json与json转table
- lua-redis中redis数据(table)转换成json
- cocos2d-x lua table与json的转换
- lua--table
- Lua table
- rails view层的具体细节(三)
- 文本编辑器nano简明使用指南
- 0014 Java接口中的成员变量【基础】
- lint优化项
- arcgis 10.2 中 制作离线包 tpk
- Lua Table to Json
- rails view层的具体细节(四)
- java泛型的解释
- poj 1755 Triathlon(半平面交解可行域)
- C++经典面试题库 附带参考答案
- 数据库初始化脚本
- 360°平滑游戏摇杆(触屏方向导航)
- DAL、DAO、ORM、Active Record辨析
- CMake+MinGW编译OpenCV-2.4.7