GetJsonFromSymbol

GetJsonFromSymbol 1:

This method generates the corresponding JSON representation of a symbol. In contrast to the AddJsonValueFromSymbol() method, the result is not written to an instance of the function block FB_JsonSaxWriter, but to a string variable. The method receives as its input parameters the data type name of the symbol as well as the address and size of the source symbol, e.g. of a structure instance. The address and size of the destination buffer that contains the JSON representation of the symbol after the call are transferred as further input parameters.

Syntax

METHOD GetJsonFromSymbol : BOOL
VAR_IN_OUT CONSTANT
  sDatatype : STRING;
END_VAR
VAR_INPUT
  nData       : UDINT;
  pData       : PVOID;
  nJson       : REFERENCE TO UDINT;
  pJson       : POINTER TO STRING;
END_VAR
VAR_OUTPUT
  hrErrorCode : HRESULT;
END_VAR

GetJsonFromSymbol 2: Return value

Name

Type

GetJsonFromSymbol

BOOL

GetJsonFromSymbol 3: Inputs

Name

Type

nData

UDINT

pData

PVOID

nJson

REFERENCE TO UDINT

pJson

POINTER TO STRING

GetJsonFromSymbol 4:/GetJsonFromSymbol 5: Inputs/Outputs

Name

Type

sDatatype

STRING

GetJsonFromSymbol 6: Outputs

Name

Type

hrErrorCode

HRESULT

GetJsonFromSymbol 7:

Input parameter nJson

The input parameter nJson contains the size of the destination buffer when the method is called, and the size of the actually written JSON object in the destination buffer when the method call is completed.

Sample call:

fbJsonDataType.GetJsonFromSymbol('ST_Values',SIZEOF(stValues), ADR(stValues), nBufferLength, ADR(sBuffer));