sitemule.github.io

Sitemule Tutorials

Looping through arrays

Arrays are important and the nice thing about working with arrays in noxDB/JSON is that there is no fixed limit on length.

noxDB has built in iterators to loop through arrays and objects easily. Both the JSON and XML APIs have this capability.

There are two main APIs we’re going to use here:


Dcl-S  Document Pointer;
Dcl-S  value    Varchar(40);
Dcl-DS list     likeds(JSON_ITERATOR);

// List elements:
Document = json_ParseString('["a","b","c"]');

// Using an iterator
list = json_SetIterator(Document);
dow json_ForEach(list); //Will stop looping when no more items have been found.
  value = json_GetStr(list.this);
enddo;

The JSON_ITERATOR structure has lots of useful subfields which you can make use of in your program: