Create JSON array of the specified size and fill it with zeros. The numeration of the array elements begins from zero. JSON array can be filled with elements of any type in any order.

 

Syntax

function JSONArraySetLength(var sJSON: string; iLength: integer): integer;

 

Parameters and return values

Parameter

Type

Value

var sJSON

string

JSON object as a text string;

iLength

integer

size of the array you want to create.

 

Function result

0

all OK; the array is created  and  placed into sJSON variable;

-1

number of array elements must be more than zero; zero array created.

 

Example


const
  SIZE = 9;
var
  sJSON: string;
  i: integer;
begin
  JSONArraySetLength(sJSON, SIZE);
  
    for i := 0 to SIZE do
      JSONArraySetInteger(sJSON, i, random(100));
      
  mLogScript(sJSON, '');
end.


Script work result

[15:35:10] (Log "JSONArraySetLenght"): [78,14,53,13,5,94,52,51,43]

[15:35:10] (Run "JSONArraySetLenght"): Script operation time: 9 ms

[15:35:10] (Run "JSONArraySetLenght"): Script done successfully.

 

See also

JSONArraySetInteger

mLogScript