我正在尝试运行手册中的 cjson 解码示例:
我似乎无法让它工作。
以下是相关配置:
location / {
content_by_lua '
local cjson = require("cjson")
json_text = '[ true, { "foo": "bar" } ]'
value = cjson.decode(json_text)
ngx.say(value)
';
resolver 8.8.8.8;
}
我收到此错误:
sudo nginx -t
nginx: [emerg] unexpected "[" in /etc/nginx/nginx.conf:29
nginx: configuration file /etc/nginx/nginx.conf test failed
如果我删除方括号,我会得到:
sudo nginx -t
nginx: [emerg] directive "content_by_lua" is not terminated by ";" in /etc/nginx/nginx.conf:28
nginx: configuration file /etc/nginx/nginx.conf test failed
有谁知道我做错了什么?似乎 cjson 应该是在 NGINX 中解析 json 的一种相当简单的方法,我知道人们正在这样做......只是无法弄清楚为什么即使是示例代码也不适合我。