Skip to content

Latest commit

 

History

History
79 lines (54 loc) · 1.93 KB

JsonDocument.md

File metadata and controls

79 lines (54 loc) · 1.93 KB

Json Document

Description

The JsonDocument contains the object model of the Json object.

Object

classDiagram
IJsonContainerElement<|--JsonDocument
IJsonContainerElement : AddElement(IJsonElement)
JsonDocument : STRING ToString()
JsonDocument : BOOL Serialize()
JsonDocument : IJsonElement GetRootElement()
JsonDocument : ClearBuffer(BOOL)
JsonDocument : Reset()

Loading

Methods

ToString() : STRING

Returns the JSON string of the JSON document (max. 254 characters)

Serialize() : BOOL

Serializes the JSON document ino a ARRAY OF CHAR. JsonDocument.buffer must be set before.

GetRootElement() : IJsonElement

Returns root element of the JSON document

AddElement(elem : IJsonElement)

Add a new element to the JSON document

ClearBuffer(hard : BOOL)

Clear the buffer logically (fast). If hard = TRUE then delete the buffer also physically (slow) JsonDocument.buffer must be set before.

Reset()

Reset the complete object tree and the destination buffer of the JSON document for the purpose, a new JSON object should be created.

Example

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