jsonGetValue (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

All

Firmware version:

2.10.00


jsonGetValue reads a JSON object or array 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 : SYSHANDLE

The value of the element. Must be freed with jsonFree when no longer needed.

 

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 jsonGetValue : INT;
VAR_INPUT
  o     : SYSHANDLE;
  idx   : INT := -1;
  key   : STRING;
  value : ACCESS SYSHANDLE;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
  rc  : INT;
  str : STRING;
  arr : SYSHANDLE;
  obj : SYSHANDLE;
END_VAR;
 
BEGIN
  ...
  // Get object from array
  rc := jsonGetValue(o := arr, idx := 0, value := obj);
  // Get name from object
  rc := jsonGetString(o := obj, key := "Name", value := str);
  // Release object handle
  rc := jsonFree(o := obj);
  ...
END;
 
END_PROGRAM;