empty Associative Array

Started by JR, February 08, 2021, 11:14:53 AM

Previous topic - Next topic

JR

0010 BEGIN                                                                                                                                                                                                                 
0020 DIM LOAD T${ALL}="[]"                                                                                                                                                                                                 
0030 FOR I$ INDEX T${ALL}                                                                                                                                                                                                   
0040 PRINT I$                                                                                                                                                                                                               
0050 NEXT I$                                                                                                                                                                                                               
->run                                                                                                                                                                                                                       


Why zero ??

Mike King

We have to provide an indication that the JSON was defined as an array, thus we insert a dummy "0" entry which will indicate that this element was an array with zero elements.

For example if you did the following:

BEGIN
DIM LOAD T${ALL}="{'cats':['Dora','Heidi'],'dogs':[]}"
PRINT DIM(LIST T${ALL})
DUMP


You would see the placeholder of "dogs.0" to indicate we have an array of dogs, its just empty thus when the JSON is recreated in the DIM(LIST...) and empty array is included.

Mike King
President - BBSysco Consulting - http://www.bbsysco.com
eMail: mike.king@bbsysco.com