PxPlus User Forum

Twitter Twitter Twitter

Author Topic: empty Associative Array  (Read 798 times)

JR

  • Member
  • **
  • Posts: 9
    • View Profile
empty Associative Array
« on: February 08, 2021, 11:14:53 AM »
0010 BEGIN                                                                                                                                                                                                                 
0020 DIM LOAD T${ALL}="[]"                                                                                                                                                                                                 
0030 FOR I$ INDEX T${ALL}                                                                                                                                                                                                   
0040 PRINT I$                                                                                                                                                                                                               
0050 NEXT I$                                                                                                                                                                                                               
->run                                                                                                                                                                                                                       


Why zero ??

Mike King

  • Diamond Member
  • *****
  • Posts: 3811
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: empty Associative Array
« Reply #1 on: February 08, 2021, 02:45:27 PM »
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:

Code: [Select]
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
eMail: mike.king@bbsysco.com