Parsing JSON with Xojo.Core.Dictionary


I’m having a little trouble parsing the result from an API into a XOJO Desktop app (Windows). I have attached the ‘template’ of how the JSON is structured and my attempt at the corresponding XOJO code.

You will see that the test for the existence of the key ‘poolDividends’ succeeds, so why does the subsequent attempt result in a KeyNotFoundException ?

For me, these 2 tests are sufficient to establish its existence:

[code]if dividend.HasKey(“poolDividends”) then

if dividend.Value(“poolDividends”) <> nil then[/code]

Must be something I’m missing ?

Thanks in advance,

You’re working with two different dictionaries.

if dividend.HasKey("poolDividends") then if dividend.Value("poolDividends") <> nil then poolDividends() = jsonDict.Value("poolDividends")
You’re checking for it in the dividend dictionary, but then asking the jsonDict for the array.

Edit: The way this JSON is formatted, the poolDividends array is a child of dividends, so you will need to access it from the dividends dictionary, not the root jsonDict.

Ah yes, thanks Tim :slight_smile: