json编码时无法区分array和dict,在"encode_empty_table_as_object"默认为"true"的情况下,t={}在使用cjson.encode(t)时会编码为{}。
使用cjson.empty_array,在json编码的时候会将其当做空数组来处理,如cjson.encode(cjson.emopty_array)编码为[]。
但在arm机器上运行时,cjson.encode(cjson.emopty_array)会编码为为空字符串。为了输出[],可以采用以下写法:
local t = {}
setmetatable(t, cjson.empty_array_mt)
cjson.encode(t)
此时可以正确编码为[]。
更深层次原因欢迎讨论~