Help iterating a JSON webhook response

Hi all, new to Xojo but I was a RealBasic user back in the 90’s! I’m trying to parse through a JSON response from a webhook and am running into a few issues getting at the content. My returned JSON from the webhook looks like this:

{
“theApps”:
[
{“label”:“App 1”,“id”:“0oapevp9gkTS5pYxZ0h7”},
{“label”:“App 2”,“id”:“0oapnv8mz7ERNRQJp0h7”},
{“label”:“App 3”,“id”:“0oararmm6vD3HtaNs0h7”},
{“label”:“App 4”,“id”:“0oawadf55cQUIARgo0h7”}
],
“statusCode”:200
}

What I’d like to do is add each app (label and id) to a new row in a listBox, but I’m having issues wrapping my head around dictionaries and variants. Right now, I can get to the list of apps as an array (I think), but I need some help cycling through the list:

Var theResponse as Dictionary = ParseJSON(content)
Var theApps as Variant = theResponse.Value(“theApps”)

thanks!

Ahh, just figured it out. I had to set theApps as an array, whcih then lets me run through each object in there:

Var theResponse as Dictionary = ParseJSON(content)

var theApps() as Variant = theResponse.Value(“theApps”)

For Each theApp As Dictionary In theApps
var theAppLabel as String = theApp.Value(“label”)
var theAppId as String = theApp.Value(“id”)
oktaAppsList.AddRow(theAppLabel, theAppId)
Next

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.