[Gambas-user] How to Disassemble XML/HTML

T Lee Davidson t.lee.davidson at gmail.com
Sat Aug 22 01:27:48 CEST 2020


On 8/21/20 2:46 PM, John Rose wrote:
> I've tried to obtain the various field values for some @type elements and some partOfSeries elements. However it now stops , I 
> think, at the line shown in the code below. I think it might be due to the first Episode 'extracted' having no partOfSeries 
> section.  How do I test for that?
> 
> aSeriesName.Add(cEpisode["partOfSeries"]["name"])
> 

The existence of a key in a collection can be tested using the Collection.Exist method. For example:
If cEpisode.Exist("partOfSeries") Then
   aSeriesName.Add(cEpisode["partOfSeries"]["name"])
   aSeriesDescription.Add(cEpisode["partOfSeries"]["description"])
End If

You don't necessarily *need* to understand the JSON data format, but it might help you determine which Gambas datatype is 
holding the particular info you want after the conversion by JSON.Decode. http://gambaswiki.org/wiki/comp/gb.util.web/json might 
help with that determination.

While taking a look at the data, I see that some elements can contain null values. For that reason, you may wish to use 
JSONCollection since it allows for that; while Collection does not. For example: Dim cEpisode As JSONCollection
JSONCollection has the same properties and methods as Collection, so it is virtually a 'drop-in' replacement.

And just FYI, a scalar variable can be defined in the same line as which it is declared:
Dim sTextContent As String = ""


-- 
Lee


More information about the User mailing list