lua-pretty-json
Lua 的漂亮 JSON 序列化器和解析器。
$ opm get xiedacon/lua-pretty-json
lua-pretty-json
[!MIT](https://github.com/xiedacon/lua-pretty-json/blob/master/LICENSE)
使用
local json = require "pretty.json"
local str = json.stringify({
"aa\"\a\v", "ccc", true, false,
{
a = "a",
b = "a",
"aaa", "ccc", "ddd",
}
}, nil, 4)
print(str)
-- [
-- "aa\"\u0007\u000b",
-- "ccc",
-- true,
-- false,
-- {
-- "1": "aaa",
-- "2": "ccc",
-- "3": "ddd",
-- "a": "a",
-- "b": "a"
-- }
-- ]
json.parse(str)
API
json.stringify(obj, replacer, space, print_address)
obj
<any>
需要序列化的值
replacer
<function>
同 js JSON.stringify
space
<number>
空格数
print_address
<boolean>
输出内存地址
json.parse(str, without_null)
str
<string>
需要反序列化的值
without_null
<boolean>
是否输出 null 值, 默认使用
json.null
json.null
许可证
版权所有 (c) 2018 xiedacon
作者
xiedacon
许可证
mit
版本
-
Lua 的漂亮 JSON 序列化器和解析器。 2019-02-12 09:28:48