我试图从ASP Classic中的Request.Form获取一系列密钥。从理论上讲,我应该只能使用Request.Form.Keys
和Request.Form.Items
,但他们根本无法工作。我明白了:
对象不支持此属性或方法:' request.form.Keys'
我尝试过制作我自己的功能,但最终却失败了.-- .Keys在Request.Form字典上运行时失败了。
我到底做错了什么????
Function dictionary_keys( dict )
Dim i
ReDim theKeys( dict.Count-1 )
for i = 0 To dict.Count-1
theKeys(i) = dict.Keys(i)
next
dictionary_keys = theKeys
End Function
Function dictionary_values( dict )
Dim i
ReDim theVals( dict.Count-1 )
for i = 0 To dict.Count-1
theVals(i) = dict.Keys(i)
next
dictionary_values = theVals
End Function
^^这两个都在dict.Keys(i)
更新:根据@Lankymart的回答,这就是我想出的:
Function request_keys( req )
Dim key, result, i
i = 0
ReDim result( req.Count-1 )
For Each key in req
result(i) = key
i = i + 1
Next
request_keys = result
End Function
Function request_values( req )
Dim key, result, i
i = 0
ReDim result( req.Count-1 )
For Each key in req
result(i) = req(key)
i = i + 1
Next
request_values = result
End Function
答案 0 :(得分:2)
Request.QueryString
和Scripting.Dictionary
个集合不是Keys
个对象,因此不支持Scripting.Dictionary
集合,但它非常简单到将它们转换为Dim dict: Set dict = Server.CreateObject("Scripting.Dictionary")
Dim key
For Each key in Request.Form
Call dict.Add(key, Request.Form(key))
Next
。
{{1}}