IJsonDocument.ReadFromStream

Syntax

ReadFromStream(Stream: IIOStreamSys);

Parameters

Stream. Stream, in which JSON structure is saved.

Description

The ReadFromStream method loads JSON structure from a stream.

Example

Sub ReadFromStream(Stream: IIOStreamSys);
Var
    Doc: IJsonDocument;
    JSON: IJsonObject;
Begin
    Doc := New JsonDocument.Create;
    Doc.ReadFromStream(Stream);
    JSON := Doc.RootElement.AsObject;
    ShowElements(JSON);
End Sub ReadFromStream;

Sub ShowElements(JSON: IJsonObject);
Var
    i, c: Integer;
    Element: IJsonElement;
Begin
    c := JSON.Count - 1;
    For i := 0 To c Do
        Element := JSON.ItemByIndex(i);
        Debug.WriteLine("Name: " + JSON.Property_(i));
        Debug.Write("Type: " + Element.GetType.ToString + ". Value: ");
        Select Case Element.GetType
            Case JsonElementType.Boolean: Debug.WriteLine(Element.AsBoolean);
            Case JsonElementType.Double: Debug.WriteLine(Element.AsDouble);
            Case JsonElementType.Integer: Debug.WriteLine(Element.AsInteger);
            Case JsonElementType.NullValue: Debug.WriteLine("null value");
            Case JsonElementType.String: Debug.WriteLine(Element.AsString);
        End Select;
    End For;
End Sub ShowElements;

The ReadFromStream function is used to get JSON structure from a stream. Information about single structure elements will be displayed in the development environment console.

See also:

IJsonDocument