jsonGetInt (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

All

Firmware version:

2.10.00


jsonGetInt reads an integer from the provided JSON object or array.

 

When working on a JSON object, set the key parameter to the name of the value to get.

When working on a JSON array, idx must be set to the index of the element to get.

 

 

Input:

o : SYSHANDLE

A handle to the JSON array or object to work on.

 

idx : INT (Default -1)

Index to use when working on a JSON array.

 

key : STRING

The name of the value when working on a JSON object.

 

Output:

value : DINT

The value of the element.

 

Returns: INT

1

- Success.

0

- Function is not supported.

-1

- Invalid key

-2

- Value not found

-3

- Invalid handle.

-4

- The type of o does not match the expected type.

-5

- Array index is outside array.

 

 

Declaration:

FUNCTION jsonGetInt : INT;
VAR_INPUT
  o     : SYSHANDLE;
  idx   : INT := -1;
  key   : STRING;
  value : ACCESS DINT;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
  rc  : INT;
  val : DINT;
  arr : SYSHANDLE;
  obj : SYSHANDLE;
END_VAR;
 
BEGIN
  ...
  // Get object from array
  rc := jsonGetValue(o := arr, idx := 0, value := obj);
  // Get integer from object
  rc := jsonGetInt(o := obj, key := "Number", value := val);
  // Release object handle
  rc := jsonFree(o := obj);
  ...
END;
 
END_PROGRAM;