jsonSetValueBool (Function)

Top  Previous  Next

Architecture:

NX32L

Firmware version:

2.10.00


jsonSetValueBool stores the provided boolean in a JSON object or array.

 

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

When working on a JSON array, idx must be set to the index of the element to set, and the insert parameter can be used to control if it should replace the existing element.

 

 

 

Input:

o : SYSHANDLE

A handle to the JSON array or object to set the value on.

 

idx : INT (Default -1)

Index to use when working on a JSON array.

Leave at -1 when working on a JSON object.

 

key : STRING

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

 

insert : BOOL (Default FALSE)

When FALSE, the existing value at the given position in the array will be replaced.

Set to TRUE to insert the value in the array at the given position and shift the elements after it one position towards the end.

 

value : BOOL

The value to add.

 

Returns: INT

1

- Success.

0

- Function is not supported.

-1

- Invalid key

-3

- Invalid handle.

-4

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

-5

- Array index is outside array.

-99

- Failed to set value

 

 

Declaration:

FUNCTION jsonSetValueBool : INT;
VAR_INPUT
   o     : SYSHANDLE;
   idx   : INT := -1;
   key   : STRING;
   insertBOOL := FALSE;
   value : BOOL;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
   rc  : INT;
   arr SYSHANDLE;
   obj SYSHANDLE;
END_VAR;
 
BEGIN
   ...
   // Create array
   rc := jsonCreateArray(:= arr);
   // Add integer
   rc := jsonAddValueInt(:= arrvalue := 123);
   // Create object
   rc := jsonCreateObject(:= obj);
   // Add boolean to object
   rc := jsonSetValueBool(:= objkey := "Enabled", value := FALSE);
   // Replace integer in array with object
   rc := jsonSetValue(:= arridx := 0value := obj);
   // Release object handle
   rc := jsonFree(:= obj);
   ...
END;
 
END_PROGRAM;