lua-cjson 例子
`apt install -y lua-cjson` 安装
编辑 tmp.lua
cjson = require "cjson"
p = 666
d = "23.42"
payload='{"d":[{"pres":'..(p)..',"temp":"'..(d)..'"}]}'
print("payload = " .. payload)j = cjson.decode(payload)
print("payload.d[1].temp = ".. j.d[1].temp)
`lua tmp.lua` 运行结果:
payload = {"d":[{"pres":666,"temp":"23.42"}]}
payload.d[1].temp = 23.42
很显然,支持 json 嵌套
lua-cjson 手册可参考这里:
https://kyne.au/%7Emark/software/lua-cjson-manual.html