Function to obtain the Boolean value of a JSON array element by index. Numeration begins from 0.

 

Syntax

function JSONArrayGetBoolean(sJSON: string; iIdx: integer; var bValue: boolean): integer;

 

Parameters and return values

Parameter

Type

Value

sJSON

string

JSON object as a text string;

iIdx

integer

index of the required array element;

var bValue

boolean

contents of the array element.

 

Function result

-1

JSON parsing error;

-2

invalid index or type of the array element;

0

function done successfully.

 

Example


const
  JSON = '[true,false,true,false,true,true,true]';
var
  iCount, i: integer;
  b: boolean;
begin
  iCount := JSONArrayLength(JSON);
  
    if iCount > 0 then
      for i := 0 to iCount - 1 do 
        if JSONArrayGetBoolean(JSON, i, b) = 0 then begin
          if b then mLogScript('YES!', IntToStr(i))
            else mLogScript('NO!', IntToStr(i));
        end;
end.


Script work result

[11:47:38] (Log "JSONArrayGetBoolean"): [0] YES!

[11:47:38] (Log "JSONArrayGetBoolean"): [1] NO!

[11:47:38] (Log "JSONArrayGetBoolean"): [2] YES!

[11:47:38] (Log "JSONArrayGetBoolean"): [3] NO!

[11:47:38] (Log "JSONArrayGetBoolean"): [4] YES!

[11:47:38] (Log "JSONArrayGetBoolean"): [5] YES!

[11:47:38] (Log "JSONArrayGetBoolean"): [6] YES!

[11:47:38] (Run "JSONArrayGetBoolean"): Script operation time: 4 ms

[11:47:38] (Run "JSONArrayGetBoolean"): Script done successfully.

 

See also

JSONArrayLength

IntToStr

mLogScript