如何在lua中编码json数组

我需要将一个带有lua表中的数组的json对象进行编码。

function encode_flow_record(type,a, b, c)
    local i = 1
    while (parent~= nil) do
         local array[i] = {f1=a,f2=b,f3=c}
         parent, a,b,c = next(a,b,c)
         i = i + 1
    end

    local datastring = cjson.encode({flowrecord=type, ancestors=array})

当我打印datastring时,它显示"ancestors":{}

我错过了什么吗?

点赞