I’ve read this from a file, and have read the key “appName” from a different file. I need to find the “appName” item in this JSON data, then find the “message” item inside it. Here’s what I’ve tried:
(nameKey is a string variable obtained elsewhere, appName is also a string. The masterJSON and appNameJSON items are JSONItem variables.)
Everything seems to be working, except for one problem… in some cases, the nameKey has a different case than what’s in the JSON data. For example, I may be given a key “APPNAME”, and have to match that to the “appName” key in the JSON data. In this case, my code fails.
I have also tried iterating over all items in masterJSON, using masterJSON.Name. I convert both nameKey and the string returned from masterJSON.Name to lowercase, and if they match, I call masterJSON.Child with the same index… and get on OutOfBoundsException on that call. No idea why.
I think this is the right idea, but you don’t have to convert to lowercase, and you can use Value instead of Child.
Off the top of my head:
dim names() as string = masterJSON.Names
dim child as JSONItem
dim pos as integer = names.IndexOf( appName )
if pos <> -1 then
child = masterJSON.Value( names( pos ) )
end if
if child <> nil then
[quote=124610:@Thomas Reed]Well, that worked perfectly, thanks!
I’ve gotta say, though, this JSONItem class needs a bit of work… it’s very unintuitive and quirky![/quote]
I’ve been doing a lot of work with the JSONItem class recently and I’ve come to think of it as very intuitive since you can use it as either an array or case-sensitive Dictionary, both of which are familiar concepts.