Sidebar

How do I use a JSON array in QIE.

0 votes
558 views
asked Oct 9, 2017 by brandon-w-8204 (33,170 points)

1 Answer

0 votes

Here is a simple example that creates an array of strings:

var i;
message.formatJSON(3);
message.setJSONArray('arrayExample');
// Populate New Array
for (i = 0; i < 10; i++) {
   message.addStringToJSONArray('arrayExample', 'ABCD' + i);
}

// Debug Whole Array
qie.debug(message.getNode('arrayExample'));

// Cycle Each Object In Array (One at a time)
// note the '/' character before the '[' 
//    to indicate that we are pulling from an array
for (i = 0; i < 10; i++) {
   var individualArrayElement = message.getNode('arrayExample/[' + (i+1) + ']');
   qie.debug(individualArrayElement);
}

The message now looks like:

{
   "arrayExample": [
      "ABCD0",
      "ABCD1",
      "ABCD2",
      "ABCD3",
      "ABCD4",
      "ABCD5",
      "ABCD6",
      "ABCD7",
      "ABCD8",
      "ABCD9"
   ]
}

The debug logs will show the whole arrayExample in the first log, and then each individual array element by itself.

In this example we only used a simple string in the array, but the array could be filled with more complex JSON objects as well.

answered Oct 9, 2017 by brandon-w-8204 (33,170 points)
...