如何通过给定的项目值显示Motobit Multi.Dictionary中的键?

我是编程新手,所以如果我的问题看起来很蠢,我很抱歉.我想问一下当我有价值时,是否有办法从
Multi.Dictionary返回密钥?

这是我的代码:

Dim myDict
Set myDict= Server.CreateObject("Multi.Dictionary")
myDict.UniqueKeys = False 

'Fill dictionary with some data
myDict("param1") = "value1"
myDict.Add "param2", "value2"
myDict.Add "param2", "value2.2"

'Get dictionary Keys
Keys = myDict.Keys
Items = myDict.Items

For Z = 0 To UBound(Items)
  Response.Write(Keys(Z) & " " & Items(Z) & "<br>")
Next

而现在回来了

Subscript out of range: ‘2’

这是正常的,因为我循环3次,而我只有2个键.

那么有可能得到这样的结果:

Param1: "value1"
Param2: "value2" 
Param2: "value2.2"

最佳答案 您可以通过检查多项或不多项来遍历myDict的键.

Dim myDict
Set myDict= Server.CreateObject("Multi.Dictionary")
myDict.UniqueKeys = False 

myDict("param1") = "value1"
myDict.Add "param2", "value2"
myDict.Add "param2", "value2.2"

Dim key, subItem
For Each key In myDict.Keys
    If IsArray(myDict(key)) Then ' item is an array
        For Each subItem In myDict(key)
            Response.Write key & ": " & subItem & "<br>"
        Next
    Else
        Response.Write key & ": " & myDict(key) & "<br>"
    End If
Next
点赞