Help parsing a JSON String

Hello everyone!
I have a quite big string of JSON data to parse that is assiget to “myJson” variable so i do…

Var d As Dictionary
d = ParseJSON(myJson)

Problem is that if i inspect the d variable i get this…


As you can see d has a key “orders” that is an array of dictionaries but shows up as a generic Object… i really would like to interate all the dictionaries inside but i do not know how to reach them, i tried different assignations but i mostly get an IllegalCastException

Anyone can give me a hint?

Thanks!

How about something like (untested code)

For each order as Dictionary in d.Orders
   ...
Next

Hello Dale, thanks for help but unfortunately it does not work, i cannot access d.orders as it’s a key value into a dictionary

Once JSON is parsed, it can only be one of two structures: a Dictionary or a Variant array. Within each of those can be values like boolean or integer, but even those are stored as Variant.

So in your case:

var d as Dictionary = ParseJSON( myJSON )
var orders() as variant = d.Value( "orders" )

for each order as Dictionary in orders // casting the Variant to Dictionary
  // process an order
next
1 Like

Thanks a lot Kem, I’ll try that!

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