Closed GunnerP closed 3 years ago
ok, solved this. You can amend items in a collection; you have to remove them and re-add them
@GunnerP what did you mean by "You can amend items in a collection; you have to remove them and re-add them". I am having the same issue.
json("b")(2) = 99
Should give you a runtime error. You need to read the Microsoft VBA object documentation for the VBA.Collection and Scripting.Dictionary objects. These objects have different interfaces and you cannot script/index between them as you would with javascript objects because of their different interfaces.
You can search for comments authored by me that have fuller descriptions and code samples on how to use these objects.
VBA Collection items are read-only (although you can modify properties of an object referenced by an item). The simplest workaround is to remove and add the item. But note that you need to specify the before position if the item order is important.
...
ModCollItem json("b"), 2, 99
...
Sub ModCollItem(coll As Collection, idx As Long, newval As Variant)
coll.Remove idx
coll.Add newval, , idx
End Sub
Anyone know why this throws an error (in Excel VBA) Dim json As Object Set json = jsonConverter.ParseJson("{""a"":123,""b"":[1,2,3,4],""c"":{""d"":456}}")
works ok but
gives a Run-time error 438