Hello!
2017-08-10 18:18 GMT-07:00 rongfeng liang:
> 你可以拷贝cjson.so 到lualib 文件,有可能是类库找不到,以前自己安装碰到多。
>
OpenResty 已经自带了 lua-cjson 库,而且必须使用 OpenResty 自带的 lua-cjson 库,因为标准的
lua-cjson 使用了 Lua 5.1 中已经废弃了的 Lua 5.0 的 C API,不再兼容最新版本的 LuaJIT,而
OpenResty 自带的 lua-cjson 是没有问题的。
我刚本地试了最新的 OpenResty 1.11.2.5 发布,使用 cjson.safe 模块,一切正常:
agentzh@imac5k ~ $ resty -V
resty 0.19
nginx version: openresty/
1.11.2.5
built by clang 8.0.0 (clang-800.0.42.1)
built with OpenSSL 1.0.2k 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx
--with-cc-opt='-O2 -I/usr/local/opt/openssl/include/
-I/usr/local/opt/pcre/include/' --add-module=../ngx_devel_kit-0.3.0
--add-module=../iconv-nginx-module-0.14
--add-module=../echo-nginx-module-0.61
--add-module=../xss-nginx-module-0.05
--add-module=../ngx_coolkit-0.2rc3
--add-module=../set-misc-nginx-module-0.31
--add-module=../form-input-nginx-module-0.12
--add-module=../encrypted-session-nginx-module-0.06
--add-module=../srcache-nginx-module-0.31
--add-module=../ngx_lua-0.10.10 --add-module=../ngx_lua_upstream-0.07
--add-module=../headers-more-nginx-module-0.32
--add-module=../array-var-nginx-module-0.05
--add-module=../memc-nginx-module-0.18
--add-module=../redis2-nginx-module-0.14
--add-module=../redis-nginx-module-0.3.7
--add-module=../rds-json-nginx-module-0.14
--add-module=../rds-csv-nginx-module-0.07
--with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib
-L/usr/local/opt/openssl/lib/ -L/usr/local/opt/pcre/lib/'
--with-http_ssl_module
agentzh@imac5k ~ $ resty -e 'ngx.say(require "cjson.safe".encode{ dogs = 32 })'
{"dogs":32}
Regards,
Yichun