jsonSetValueFloat (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

All

Firmware version:

2.10.00


jsonSetValueFloat stores the provided floating point value 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 : DOUBLE

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.

-6

- Not enough resources available to add value.

-99

- Failed to set value

 

 

Declaration:

FUNCTION jsonSetValueFloat : INT;
VAR_INPUT
  o     : SYSHANDLE;
  idx   : INT := -1;
  key   : STRING;
  insert: BOOL := FALSE;
  value : DOUBLE;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
  rc  : INT;
  arr : SYSHANDLE;
  obj : SYSHANDLE;
END_VAR;
 
BEGIN
  ...
  // Create array
  rc := jsonCreateArray(o := arr);
  // Add integer
  rc := jsonAddValueInt(o := arr, value := 123);
  // Create object
  rc := jsonCreateObject(o := obj);
  // Add float to object
  rc := jsonSetValueFloat(o := obj, key := "Number", value := 12.3);
  // Replace integer in array with object
  rc := jsonSetValue(o := arr, idx := 0, value := obj);
  // Release object handle
  rc := jsonFree(o := obj);
  ...
END;
 
END_PROGRAM;