已解决,原来是序列化的问题。
https://groups.google.com/d/msg/openresty/hdOdVyK2K3U/3K784aeyok8J
On Tuesday, December 25, 2012 7:20:53 PM UTC+8, smallfish wrote:
恩,是有点问题。先自己用 pairs 来输出一下吧,回头我看看 ngx.say 部分。
你可以先这样输出:
for k in pairs(lua_table) do
v = lua_table[k]
if type(v) == "table" then
for k2 in pairs(lua_table[k]) do
ngx.say(k, k2, lua_table[k][k2])
end
else
ngx.say(k, lua_table[k])
end
end
On Tue, Dec 25, 2012 at 6:21 PM, Bill Zhu
<bill...@gmail.com> wrote:
RT。
location /t {
charset utf-8;
content_by_lua '
cjson = require "cjson"
local json_text = [=[[ true, { "foo": "bar" } ]]=]
ngx.say(json_text)
local lua_table = cjson.decode(json_text)
ngx.say(lua_table[2].foo)
';
}
location /t2 {
charset utf-8;
content_by_lua '
cjson = require "cjson"
local json_text = [=[[ true, { "foo": "bar" } ]]=]
ngx.say(json_text)
local lua_table = cjson.decode(json_text)
ngx.say(lua_table)
';
}
访问t可输出bar,而访问t2却出现如下:
[error] 1832#0: *3 lua entry thread aborted: runtime error: [string "content_by_lua"]:6: bad argument #1 to 'say' (non-array table found)
stack traceback:
coroutine 0:
[C]: in function 'say'
[string "content_by_lua"]:6: in function <[string "content_by_lua"]:1>
请问如何解决?