StefanA
(StefanA)
August 25, 2023, 7:18am
1
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?
https://drive.google.com/file/d/1fFZ2rbo8agVs4Yxtp7eE-yzdHq27aXYT/view?usp=drive_link
StefanA
(StefanA)
August 25, 2023, 7:40am
2
I was able to replicate the issue
https://tracker.xojo.com/xojoinc/xojo/-/issues/73787
Var json As New JSONItem
Var result As Integer = json.Lookup("test", 0) // WORKS
json.RemoveAll
Var result2 As Integer = json.Lookup("test", 0) // THROWS EXCEPTION
3 Likes
Greg_O
(Greg O)
August 25, 2023, 9:29am
3
@StefanA
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.
StefanA
(StefanA)
August 25, 2023, 9:51am
4
Dictionary does not have this issue.
This code works as expected:
Var d As New Dictionary
Var i As Integer = d.Lookup("test", 0)
d.RemoveAll
Var i2 As Integer = d.Lookup("test", 0)
Greg_O
(Greg O)
August 25, 2023, 10:03am
5
You should put that in your case
Greg_O
(Greg O)
August 25, 2023, 10:06am
6
That said, you could just reinitialize the JSONItem with new
to get the same effect.
DerkJ
(DerkJ)
August 25, 2023, 2:03pm
7
I remember having this same issue when i used removeAll (jsonitem) and then got the exception…