我有以下由我的dataTable创建的查询字符串:
http://testserver/cgi-bin/widget?draw=1&columns%5B0%5D%5Bdata%5D=0&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=1&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=true&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=2&columns%5B2%5D%5Bname%5D=&columns%5B2%5D%5Bsearchable%5D=true&columns%5B2%5D%5Borderable%5D=true&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B3%5D%5Bdata%5D=3&columns%5B3%5D%5Bname%5D=&columns%5B3%5D%5Bsearchable%5D=true&columns%5B3%5D%5Borderable%5D=true&columns%5B3%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B3%5D%5Bsearch%5D%5Bregex%5D=false&order%5B0%5D%5Bcolumn%5D=1&order%5B0%5D%5Bdir%5D=asc&start=0&length=10&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1431373301322
从我的cgi脚本中,我可以通过执行类似
的操作来提取“draw”和“start”等值local start = FORM.start
local draw = FORM.draw
但我需要知道如何获得其他值。在FFox中的F12工具中,我可以看到我有像[1] [data]:1这样的值,但我似乎无法获得正确的语法来获取这些值。在我上面显示的查询字符串中,此值被发送/发布为“columns%5B1%5D%5Bdata%5D = 1”
我尝试了以下组合:
--log(FORM.columns.1.data)
--log(FORM.columns[1][data])
--log(FORM.columns[1]['data'])
--log(FORM.columns['1']['data'])
我还在lua命令行上运行了一些测试,以确保我知道如何访问存储在多维数组中的值
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
> mt = {}
> mt[1]={}
> mt[1]['data']=1
> print(mt[1].data)
1
> print(mt[1]['data'])
1
>
任何建议将不胜感激。 感谢。
答案 0 :(得分:0)
查询字符串是percent encoded,因为查询字符串不具有例如{3}。括号内。您必须先解码它才能使用它。 Here是如何执行此操作的示例(在页面末尾)。这两种方法:
function unescape (s)
s = string.gsub(s, "+", " ")
s = string.gsub(s, "%%(%x%x)", function (h)
return string.char(tonumber(h, 16))
end)
return s
end
使用的
cgi = {}
function decode (s)
for name, value in string.gfind(s, "([^&=]+)=([^&=]+)") do
name = unescape(name)
value = unescape(value)
cgi[name] = value
end
end