JsonArrayGetArrayElement Function

Action

Retrieves the value of a specified element from a JSON array. If the array element does not exist in the JSON array or the array element does not contain a JSON array value nothing happens.

Include file

Json.bdh

Syntax

JsonArrayGetArrayElement( in  handle : number,
                          in  index  : number,
                          out value  : number ): boolean;
Parameter Description
handle Valid handle to a JSON array
index The index position in the JSON array. Lower bound is zero (0).
value Parameter that contains the value of the specified element. The value is a handle to a JSON array.

Return value

  • true if element successfully found
  • false otherwise

Example

transaction TMain
var
  jsonText, elementValue       : string;
  jsonArray, nestedArray, i, j : number;
begin
  WebParseDataBound(jsonText);
  WebPageUrl("http://mycompany.com/api/jsondata");
  jsonArray := JsonParse(jsonText);
  
  for i := 0 to (JsonGetArrayLength(jsonArray) - 1) do
    //get nested array
    JsonArrayGetArrayElement(jsonArray, i, nestedArray);
	Print("Array at index " + string(i));
	//iterate over nested array
	for j := 0 to (JsonGetArrayLength(nestedArray) - 1) do
      JsonArrayGetStringElement(nestedArray, j, elementValue);
	  Print("index: " + string(j) + ", value: " + elementValue);
	end;
  end;

  JsonFree(jsonArray);
end TMain;