jsonToString (Function)

Top  Previous  Next

Architecture:

NX32L

Firmware version:

2.10.00


jsonToString creates a string representation of the JSON structure.

If indent is set to 0, it will be a compact string with no indentation or newlines, otherwise it will use newlines between items and use indentation.

 

Input:

o : SYSHANDLE

A handle to the JSON structure.

 

indent: SINT (0..31, Default 3)

The number of spaces to use for indentation. If set to 0, the string will not use indentation and will be on a single line.

 

Output:

str : STRING

The generated string.

 

Returns: INT

1

- Success

0

- Function is not supported.

-1

- Invalid indentation.

-3

- Invalid handle.

-99

- Failed to create string, structure might be corrupt.

 

 

Declaration:

FUNCTION jsonToString : INT;
VAR_INPUT
   o      : SYSHANDLE;
   indent : INT := 3;
   str    : ACCESS STRING;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
   rc  : INT;
   obj SYSHANDLE;
   str STRING;
END_VAR;
 
BEGIN
   ...
   // Create structure from string
   rc := jsonFromString(:= objstr := "[{$"name$":$"Test Object$"}]");
 
   // Dump structure to device output
   rc := jsonToString(:= objindent:=3str := str);
   DebugMsg(message:=str);
   ...
END;
 
END_PROGRAM;