JSON Parsing - Accessing Dictionary Nested Within Auto(), Nested Within Auto()

I am having an issue accessing a Dictionary that’s being created when I’m getting patient information from an EMR provider (Athena). I’m having no issues iterating through patient records when I search by patient name and DOB… I get a Dictionary nested within another Dictionary and I can work with this. HOWEVER, when I do a GET by Patient ID, it returns an Auto() nested within another Auto() which contains the Dictionary.

So, can anyone tell me how I access an Auto() value within another Auto()? I believe it’s essentially an array within another array, right?

Sub PageReceived(url as string, httpStatus as integer, headers as internetHeaders, content as string)
Dim buffer As Text = content.defineEncoding(Encodings.UTF8).convertEncoding(Encodings.UTF8).ToText
Dim cHeaders As InternetHeaders = headers 'This isn’t really necessary…just prevents warning when compiled
cHeaders = cHeaders 'This isn’t really necessary…just prevents warning when compiled

// Add brackets so JSON is well-formed and we parse to create a dictionary (“records”)
buffer = “[” + buffer +"]"

Dim records() As Auto = Xojo.Data.ParseJSON(buffer) 'Gets parsed JSON data in form of Dictionary or array of Dictionaries

Dim rec As Xojo.Core.Dictionary = records(0)

Here’s an image that might make things clearer:

Something like:

Dim recs() As Xojo.Core.Dictionary = records 
Dim currentRec As Xojo.Core.Dictionary = recs(0)

Derk - thank you…I’m pretty sure this is what I’m doing but I’m getting an OutofBoundsException error. The problem is that the Dictionary is nested within another Auto() . Please see my attached image.

Thanks!

Have you tried

dim recs() as Auto = records(0)
dim currentRecord as Xojo.Core.Dictionary = recs(0)

[quote=437565:@Aaron Schacht]Derk - thank you…I’m pretty sure this is what I’m doing but I’m getting an OutofBoundsException error. The problem is that the Dictionary is nested within another Auto() . Please see my attached image.

Thanks![/quote]

In your fist post you see:
Records | Auto(0)
That means there is 1 item of type auto in your records() As Auto array.

You should be checking if records().ubound <> -1
And also keep track of the ubound in loops.

I don’t see where you get the OutOfBoundsException.

If the array has other arrays in it you should be selecting the right thing, that is probably:

Dim RecordsDicts() As Xojo.Core.Dictionary = records
Dim Record As Xojo.Core.Dictionary = RecrodsDict(0)

But do check if the index actually exists.

@Tim Hare This got me on the right track…thank you! Your suggestion, along with some other changes to my code got everything working.

@Derk Jochems Thank you for giving me some other ideas of how to work with Dictionaries!