Auto is an array of nothings ??

Greetings All,

I have a JSON string downloaded from a website API. The string contains JSON items with what amounts to dictionaries and arrays of dictionaries. The usual JSON stuff.

I want to dig through the JSON, so I make an auto according to the methods shown in the Language reference.

dim xjd() as auto xjd = Xojo.Data.ParseJSON(tx)

Then I loop through xjd according to LR method. This works, because xjd is recognised as an array of dictionaries.

[code]For each dJ as xojo.Core.Dictionary in xjd

dataLevelOne = dj.value("data")
info2 = Xojo.Introspection.GetType(dataLevelOne)

dLTwoText = Xojo.Data.GenerateJSON(dataLevelOne.value("data"))
dataLevelTwo = Xojo.Data.ParseJSON(dLTwoText)

info = Xojo.Introspection.GetType(dataLevelTwo)

next[/code]

But now I have a difficulty. dataLevelTwo is considered by Introspection as an array of Autos (it is in fact an array of dictionaries, according to the debugger).

So this code will refuse to compile, failing with a TypeMismatch.

for each item as xojo.core.dictionary in dataLevelTwo info2 = Xojo.Introspection.GetType(item) next

This code also fails to compile, considering that dataLevelTwo is not an array but I am treating it as one.

   [code]for each item as auto in dataLevelTwo

info2 = Xojo.Introspection.GetType(item)
next[/code]

How do I access the dictionaries within dataLevelTwo ?

Your code confuses me, but more on that later.

You didn’t show your declaration of dataLevelTwo but I suspect you dim’d it as Auto, and that’s not an array. Instead you have to dim it as Auto(), at which point each element can be assigned to item as Xojo.Core.Dictionary.

As for why your code confuses me, it seems like you parse the JSON into arrays and Dictionaries, go down one level, then convert it to JSON again, then back again. This is unnecessary as dataLevelOne.Value( “data” ) already has the objects you need.

I’ll try that …

Thank you Kem. Much appreciated.

Regards, Tony Barry