开源软件名称(OpenSource Name):bungle/lua-resty-libcjson开源软件地址(OpenSource Url):https://github.com/bungle/lua-resty-libcjson开源编程语言(OpenSource Language):Lua 100.0%开源软件介绍(OpenSource Introduction):lua-resty-libcjson
InstallationJust place Compiling and Installing cJSON C-libraryThese are just rudimentary notes. Better installation instructions will follow:
Using LuaRocks or MoonRocksIf you are using LuaRocks >= 2.2: $ luarocks install lua-resty-libcjson If you are using LuaRocks < 2.2: $ luarocks install --server=http://rocks.moonscript.org moonrocks
$ moonrocks install lua-resty-libcjson MoonRocks repository for Lua APImixed json.decode(value)Decodes JSON value or structure (JSON array or object), and returns either Lua Examplelocal json = require "resty.libcjson"
local obj = json.decode "{}" -- table (with obj.__jsontype == "object")
local arr = json.decode "[]" -- table (with arr.__jsontype == "array")
local nbr = json.decode "1" -- 1
local bln = json.decode "true" -- true
local str = json.decode '"test"' -- "test"
local str = json.decode '""' -- ""
local num = json.decode(5) -- 5
local num = json.decode(math) -- math
local num = json.decode(json.null) -- json.null
local nul = json.decode "null" -- json.null
local nul = json.decode "" -- nil
local nul = json.decode(nil) -- nil
local nul = json.decode() -- nil Nested JSON structures are parsed as nested Lua tables. string json.encode(value, formatted)Encodes Lua value or table, and returns equivalent JSON value or structure as a string. Optionally you may pass Examplelocal json = require "resty.libcjson"
local str = json.encode{} -- "[]"
local str = json.encode(setmetatable({}, json.object)) -- "{}"
local str = json.encode(1) -- "1"
local str = json.encode(1.1) -- "1.100000"
local str = json.encode "test" -- '"test"'
local str = json.encode "" -- '""'
local str = json.encode(false) -- "false"
local str = json.encode(nil) -- "null"
local str = json.encode(json.null) -- "null"
local str = json.encode() -- "null"
local str = json.encode{ a = "b" } -- '{ "a": "b" }'
local str = json.encode{ "a", b = 1 } -- '{ "1": "a", "b": 1 }'
local str = json.encode{ 1, 1.1, "a", "", false } -- '[1, 1.100000, "a", "", false]' Nested Lua tables are encoded as nested JSON structures (JSON objects or arrays). About JSON Arrays and Object Encoding and DecodingSee this comment: #1 (comment). BenchmarksAbout 190 MB citylots.json: # Lua cJSON
Decoding Time: 5.882825
Encoding Time: 4.902301
# lua-resty-libcjson
Decoding Time: 6.409872
Encoding Time: (takes forever) License
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论