我有点进退两难。我收到一个数组数组,其中包含数组的第一个元素中的字符串,表示哈希 {HASH}。我不知道数组数组的结构,它可以根据不同调用的结果而有所不同。数据示例如下:
[ [ "{HASH}", 1000, ["{HASH}", "A", 100], ["{HASH}", "B", 150], ["{HASH}", "C", 200] ],
[ "{HASH}", 1001, ["{HASH}", "D", 101], ["{HASH}", "E", 151], ["{HASH}", "F", 201] ]
]
哈希应该如下所示:
{1000}{A}=100
{1000}{B}=150
{1000}{c}=200
{1001}{D}=101
{1001}{E}=151
{1001}{F}=201
我已经编写了以下函数以递归调用以输出数组中的条目这很好,但我需要将其放入定义的哈希中,这是失败的地方,因为它被递归调用,哈希被重置ETC:
Public Function ProcessObjOrArray(Obj As Variant, key As String, ByRef hashIn, HashCreated As Boolean) As Variant
Dim sKey As String
Dim i As Integer
Dim objRes As Variant
If HashCreated = False Then
Dim hash
HashCreated = True
Set hash = CreateObject("Scripting.Dictionary")
End If
If IsArray(Obj) Then
For i = 0 To UBound(Obj, 1)
objRes = ProcessObjOrArray(Obj(i), sKey, hash, HashCreated)
If (objRes = "{HASH}") Then
i = i + 1
sKey = Obj(i)
End If
Next i
If key <> "" Then
Debug.Print "Adding {" + key + "}=AllTheStuff"
Set hash.Item(key) = hashIn
Dim a
a = hash.Item(key)("Enabled")
Exit Function
End If
Else
If key <> "" Then
Debug.Print "Adding {" + key + "}=" + CStr(Obj)
hash.Item(key) = Obj
Else
ProcessObjOrArray = Obj
End If
End If
End Function
传入的 Object 显然是我上面定义的数组。如果有人有这样做的聪明方法,将不胜感激。