Can't match a string key in Xojo.Core.Dictionary created through ParseJSON

Consider this JSON:


Looks harmless enough, right? But now try this:

dim d as Xojo.Core.Dictionary = Xojo.Data.ParseJSON( kThatJSON )
dim key1 as string = "CompleteTimestamp"
dim key2 as string = "CompletedUserId"

dim a1 as auto = d.Value( key1 ) // This is fine
dim a2 as auto = d.Value( key2 ) // KeyNotFoundException — What?!?

If instead you use Text keys, or recreate this as a “normal” Dictionary (not the case-sensitive one produced by ParseJSON), it works. See the report and a better example project at:


This is the same problem in multiple languages.

You can’t get a value because none exists. Null is undefined.

If you need to store nulls, serialise them into something unique.

I can’t give you some code as I’m away from my computer, see haskey

I think the error comes from the key starting with “Completed”. Test it: any key containing “Completed” will fail:

“Completed” fails
“CompletedUser” fails
“CompletedUserId” fails
“CompletedBlablabla” fails
“UnCompleted” fails
“UnCompletedBlablabla” fails

“CompleteUserId” works (note the missing d)

So this is an error in the JSON library.

Julian, it doesn’t have to do with the values. When I found the issue, the keys all had values assigned, and there were a lot more of them.

Eli, that’s interesting. But as noted, only when you try to use a string key, not text. Is there a Feedback report about this already? If so, I’ll make a note in mine to link them.

Not that I know of.

Oh wow that is a problem then :slight_smile: teaches me for posting from my iPad without testing :wink: