遇到cjson.decode后,遍历这个table,找不到参数的问题,求教

44 views
Skip to first unread message

tan winfan

unread,
Dec 21, 2018, 5:49:56 AM12/21/18
to openresty
    local req = self.params
    local dev = {}
    dev["devId"] = req["devId"] 
    local devInfo = cjson.decode(self.params.devInfo) -- 我这个参数是json

    --把devinfo所有值遍历存放到dev
    for k, v in ipairs(devInfo) do  
        dev[string.lower(k)] = v --这里打印为空,devInfo tabla 长度为0是怎么回事
    end

quzhi

unread,
Dec 24, 2018, 8:33:32 PM12/24/18
to openresty
hi
  ipairs 只能遍历数组,你可以使用pairs

在 2018年12月21日星期五 UTC+8下午6:49:56,tan winfan写道:

tianxia...@gmail.com

unread,
Dec 26, 2018, 1:56:07 AM12/26/18
to openresty
ipairs 是自然KEY  你试试pairs


在 2018年12月21日星期五 UTC+8下午6:49:56,tan winfan写道:
    local req = self.params
Reply all
Reply to author
Forward
0 new messages