The JsonDocument contains the object model of the Json object.
classDiagram
IJsonContainerElement<|--JsonDocument
IJsonContainerElement : AddElement(IJsonElement)
JsonDocument : STRING ToString()
JsonDocument : BOOL Serialize()
JsonDocument : IJsonElement GetRootElement()
JsonDocument : ClearBuffer(BOOL)
JsonDocument : Reset()
Returns the JSON string of the JSON document (max. 254 characters)
Serializes the JSON document ino a ARRAY OF CHAR. JsonDocument.buffer must be set before.
Returns root element of the JSON document
Add a new element to the JSON document
Clear the buffer logically (fast). If hard = TRUE
then delete the buffer also physically (slow) JsonDocument.buffer must be set before.
Reset the complete object tree and the destination buffer of the JSON document for the purpose, a new JSON object should be created.
USING Simatic.Ax.Json;
USING AxUnit.Assert;
NAMESPACE Simatic.Ax
CLASS JsonExample
VAR PUBLIC
END_VAR
VAR PROTECTED
doc : JsonDocument;
e1 : JsonDoubleInt := (key := 'Element1', value := 1);
e2 : JsonDoubleInt := (key := 'Element2', value := 2);
e3 : JsonDoubleInt := (key := 'Element3', value := 3);
o1 : JsonObject := (key := 'NestedObject');
END_VAR
METHOD PUBLIC Init;
// Example String:
// {"Element1": 1, {"Element2": 2, "Element3": 3}}
doc.AddElement(e1).AddElement(o1);
o1.AddElement(e2).AddElement(e3);
END_METHOD
METHOD PUBLIC ToString : STRING
ToString := doc.ToString();
END_METHOD
END_CLASS
END_NAMESPACE