Function to obtain an integer from a JSON array by index. Numeration begins from 0.

 

Syntax

function JSONArrayGetInteger(sJSON: string; iIdx: integer; var iValue: integer): 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 iValue

integer

the 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 = '[1,4,1,5,9,2,6]';
var
  iCount, i, x: integer;
  s: string;
begin
  iCount := JSONArrayLength(JSON);
  
    if iCount > 0 then begin
      s := '3,';
        for i := 0 to iCount - 1 do 
          if JSONArrayGetInteger(JSON, i, x) = 0 then 
            s := s + IntToStr(x);
      mLogScript('Pi number: ' + s, '');
    end;
end.


Script work result

[11:30:02] (Log "JSONArrayGetInteger"): Pi number: 3,1415926

[11:30:02] (Run "JSONArrayGetInteger"): Script operation time: 6 ms

[11:30:02] (Run "JSONArrayGetInteger"): Script done successfully.

 

See also

JSONArrayLength

IntToStr

mLogScript