krisLB7
New Member
- Joined
- Jun 25, 2020
- Messages
- 5
- Office Version
- 2019
- Platform
- Windows
- MacOS
- Mobile
- Web
I'm struggling with something simple that I feel I am missing the obvious.
I am looking to nest a dictionary that has ~25 pairs in it into a dictionary. The final structure I'm expecting is:
dict1 = { "parent", dict2 }
dict2 = { "a", 1 }, { "b", 2 }, ....., { "e", 6 }
------
{
"parent" : {
"a" : 1,
"b" : 2,
"c" : 3,
"d" : 4
}
}
But it's setting a null value for the parent value instead, and the debug print is err'ing out at that part as well. I'm just looking to nest a dictionary, not create a dictionary of dictionaries.
------
Sub main()
Dim dict2 As Object
Set dict2 = CreateObject("Scripting.Dictionary")
dict2.Add "a", 1
dict2.Add "b", 2
dict2.Add "c", 3
dict2.Add "d", 4
Dim dict1 As Object
Set dict1 = CreateObject("Scripting.Dictionary")
dict1.Add "parent", dict2
Debug.Print "--dict2-------"
Dim okey2 As Variant
For Each okey2 In dict2.keys
Debug.Print okey2, dict2(okey2)
Next
Debug.Print "--dict1-------"
Dim okey1 As Variant
For Each okey1 In dict1.keys
Debug.Print okey1, dict1(okey1)
Next
End Sub
I am looking to nest a dictionary that has ~25 pairs in it into a dictionary. The final structure I'm expecting is:
dict1 = { "parent", dict2 }
dict2 = { "a", 1 }, { "b", 2 }, ....., { "e", 6 }
------
{
"parent" : {
"a" : 1,
"b" : 2,
"c" : 3,
"d" : 4
}
}
But it's setting a null value for the parent value instead, and the debug print is err'ing out at that part as well. I'm just looking to nest a dictionary, not create a dictionary of dictionaries.
------
Sub main()
Dim dict2 As Object
Set dict2 = CreateObject("Scripting.Dictionary")
dict2.Add "a", 1
dict2.Add "b", 2
dict2.Add "c", 3
dict2.Add "d", 4
Dim dict1 As Object
Set dict1 = CreateObject("Scripting.Dictionary")
dict1.Add "parent", dict2
Debug.Print "--dict2-------"
Dim okey2 As Variant
For Each okey2 In dict2.keys
Debug.Print okey2, dict2(okey2)
Next
Debug.Print "--dict1-------"
Dim okey1 As Variant
For Each okey1 In dict1.keys
Debug.Print okey1, dict1(okey1)
Next
End Sub