如何通过给定的项目值显示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.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

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....