I have a problem in one of our projects where a class with JSONItem as super class throws a KeyNotFoundException on Me.Lookup(key, Nil).
I copied the same class into a demo project and removed everything that is not relevant, but I don’t get the error recreated.
What could be the reason for this?
I was able to replicate the issue
Var json As New JSONItem
Var result As Integer = json.Lookup("test", 0) // WORKS
Var result2 As Integer = json.Lookup("test", 0) // THROWS EXCEPTION
Have you tried that same thing with a Dictionary? JSONItem was changed to use a Dictionary and GenerateJSON a few years ago for the speed so I would expect it to have the same issue.
Dictionary does not have this issue.
This code works as expected:
Var d As New Dictionary
Var i As Integer = d.Lookup("test", 0)
Var i2 As Integer = d.Lookup("test", 0)
You should put that in your case
That said, you could just reinitialize the JSONItem with
new to get the same effect.
I remember having this same issue when i used removeAll (jsonitem) and then got the exception…