AddJsonKeyValueFromSymbol

AddJsonKeyValueFromSymbol 1:

This method generates the JSON representation of a PLC data structure on an FB_JsonSaxWriter object. The method receives as its input parameters the instance of the FB_JsonSaxWriter function block, the data type name of the structure, and the address and size of the source structure instance. As a result, the FB_JsonSaxWriter instance contains a valid JSON representation of the structure. Unlike the method AddJsonValueFromSymbol(), the elements of the source structure are nested here in a JSON sub-object whose name can be specified via the input/output parameter sKey.

Syntax

METHOD AddJsonValueFromSymbol : BOOL
VAR_IN_OUT
  fbWriter    : FB_JsonSaxWriter;
END_VAR
VAR_IN_OUT CONSTANT
  sKey        : STRING;
  sDatatype   : STRING;
END_VAR
VAR_INPUT
  nData       : UDINT;
  pData       : PVOID;
END_VAR
VAR_OUTPUT
  hrErrorCode : HRESULT;
END_VAR

AddJsonKeyValueFromSymbol 2: Return value

Name

Type

AddJsonValueFromSymbol

BOOL

AddJsonKeyValueFromSymbol 3: Inputs

Name

Type

nData

UDINT

pData

PVOID

AddJsonKeyValueFromSymbol 4:/AddJsonKeyValueFromSymbol 5: Inputs/Outputs

Name

Type

fbWriter

FB_JsonSaxWriter

sKey

STRING

sDatatype

STRING

AddJsonKeyValueFromSymbol 6: Outputs

Name

Type

hrErrorCode

HRESULT

A complete sample of how to use this method can be found in section Tc3JsonXmlSampleJsonDataType.

Sample call:

fbJsonSaxWriter.ResetDocument()
fbJsonDataType.AddJsonKeyValueFromSymbol(fbJsonSaxWriter, 'Values','ST_Values',SIZEOF(stValues), ADR(stValues));