lua:lua_cjson
Lua CJSON
The Lua CJSON module provides JSON support for Lua.
Features
- Fast, standards compliant encoding/parsing routines
- Full support for JSON with UTF-8, including decoding surrogate pairs
- Optional run-time support for common exceptions to the JSON specification (infinity, NaN,..)
WebHMI supports this module starting from version WebHMI 3.4.
Documentation for CJSON module is available at official site.
There are 2 most important functions: cjson.encode and cjson.decode.
cjson.encode will serialise a Lua value into a string containing the JSON representation.
Example:
value = { true, { foo = "bar" } } json_text = cjson.encode(value) -- Returns: '[true,{"foo":"bar"}]'
cjson.decode will deserialise any UTF-8 JSON string into a Lua value or table.
Example:
json_text = '[ true, { "foo": "bar" } ]' value = cjson.decode(json_text) -- Returns: { true, { foo = "bar" } }
If your task is extract from the 7bit LoRA AirGate's JSON package then use to following code
- Extract AirGate JSON value
local encoded = GetReg("encoded_json") local decoded_table = cjson.decode(encoded) for i, v in pairs(decoded_table) do TRACE(i .. " = " .. tostring(v)) -- show all the content of packet. end temp_int = decoded_table.temp_int -- example of extraction
lua/lua_cjson.txt ยท Last modified: 2021/12/07 11:22 by atolstov