WriteToStream(Stream: IIOStreamSys; [Options: JsonFormatOptions =0])
WriteToStream(Stream: System.IO.Stream; Options: Prognoz.Platform.Interop.ForeSystem.JsonFormatOptions)
Stream. Stream, to which JSON structure is to be saved.
Options. View format when writing.
The WriteToStream method writes JSON structure to a stream.
Add links to the IO, ForeSystem (for the Fore.NET example) system assemblies.
Function CreateJson: IIOStreamSys;
Var
NewJSON: IJsonObjectBuilder;
Doc: IJsonDocument;
MemStr: IMemoryStream;
Begin
NewJSON := New JsonObjectBuilder.Create;
NewJSON.AddBoolean("Bool", True);
NewJSON.AddDouble("Double", 3.14);
NewJSON.AddInteger("Integer", 100);
NewJSON.AddNull("Null");
NewJSON.AddString("String", "Test JSON");
NewJSON.AddBoolean("Bool", True);
// Save to stream
Doc := New JsonDocument.Create;
Doc.Root := NewJSON.Build;
MemStr := New MemoryStream.Create;
Doc.WriteToStream(MemStr);
Return MemStr;
End Function CreateJson;
Imports Prognoz.Platform.Interop.ForeSystem;
Function CreateJson(): System.IO.Stream;
Var
NewJSON: IJsonObjectBuilder = New JsonObjectBuilderClass();
Doc: IJsonDocument = New JsonDocumentClass();
MemStr: System.IO.MemoryStream = New System.IO.MemoryStream();
Begin
NewJSON.AddBoolean("Bool", True);
NewJSON.AddDouble("Double", 3.14);
NewJSON.AddInteger("Integer", 100);
NewJSON.AddNull("Null");
NewJSON.AddString("String", "Test JSON");
NewJSON.AddBoolean("Bool", True);
// Save to stream
Doc.Root := NewJSON.Build();
Doc.WriteToStream(MemStr, JsonFormatOptions.jfoDefault);
Return MemStr;
End Function;
The specified function creates a new JSON structure with a set of elements. The function results in the stream, to which JSON structure is saved.
See also: