Método 1: use lua-cjson
1 | luarocks install lua-cjson |
Resultado:
1 2 3 4 5 6 7 8 | [root@tutorialspots ~]# luarocks install lua-cjson gcc -O2 -fPIC -I/usr/local/include/luajit-2.1 -c lua_cjson.c -o lua_cjson.o gcc -O2 -fPIC -I/usr/local/include/luajit-2.1 -c strbuf.c -o strbuf.o gcc -O2 -fPIC -I/usr/local/include/luajit-2.1 -c fpconv.c -o fpconv.o gcc -shared -o cjson.so -L/usr/local/lib lua_cjson.o strbuf.o fpconv.o No existing manifest. Attempting to rebuild... lua-cjson 2.1.0.6-1 is now installed in /usr/local (license: MIT) |
Ejemplo:
1 2 3 4 5 | local json_string = "{\"website\":\"www.tutorialspots.com\"}" local json = require( 'cjson' ) local tab = json.decode(json_string) json_string = json.encode(tab) print(json_string) |
Resultado:
1 | {"website":"www.tutorialspots.com"} |
Demostración en línea: aquí
Método 2: use json4lua
1 | wget -q https://raw.githubusercontent.com/Egor-Skriptunoff/json4lua/master/json.lua -O /usr/local/lib/lua/resty/json.lua |
Ejemplo:
1 2 3 4 5 | local json_string = "{\"website\":\"www.tutorialspots.com\"}" local json = require( 'json' ) local tab = json.decode(json_string) json_string = json.encode(tab) print(json_string) |
Método 3: use json.lua
1 | wget -q https://raw.githubusercontent.com/rxi/json.lua/master/json.lua -O /usr/local/lib/lua/resty/json.lua |
Términos de búsqueda recientes:
- 1337 xt idioma: en
0 Comentarios
Dejanos tu comentario para seguir mejorando!