I am having “fun” parsing some JSON and I am slowing navigating my way through the tree.
But I have hit a bit of a snag.
Each level is Xojo.Core.Dictionary.
For the third level down I see:
Row 1: Name =
Value = Contents
Row 2: Name = Count
Value = 24
The data I need to get to is in the “Contents”.
I have tried:
Level4 = Level3.Lookup(nil,"NotFound")
and
Level4 = Level3.Lookup("","NotFound")
The error I get back is:
TypeMismatchException "Expected Object but got Text"
Make your lookup backup nil and check for nil to see if Level4 was found. The default value needs to be similar to the actual value you’re expecting, so if Level4 is a JSONItem (Object in the JSON) then the default value needs to be an object.
But also, you can’t lookup “” because there’s no key to be looking up.
Perhaps, share the JSON response and we can help you figure out how to parse it?
Contents, blue and underlined probably means in the debugger, looking at the JSONItem, right? That won’t tell us a whole lot about the goal unfortunately.
From the JSON provided, what values are you looking to get a hold of?
When I interact with APIs I have found it easier to create classes that behave like the objects I’m expecting and parse the JSON into those objects. That way, it’s almost like using ActiveRecord for API interaction.
I am trying to get hold of the counts.
This is a rolling count of the each API interface usage on an hourly basis and we need to keep a daily history for trending.
You’re looking at the debugger’s display of the dictionary object itself (which coincidentally has a property named “Count”, which may be confusing you), not what’s in the dictionary (the JSON). Click on “Contents” to see what is in the dictionary. Blue and underlined indicates a link that you can click on.