WriteToFile(FileName: String; [Options: JsonFormatOptions =0]);
WriteToFile(FileName: String; Options: Prognoz.Platform.Interop.ForeSystem.JsonFormatOptions);
FileName. Путь и наименование JSON-файла.
Options. Формат представления при записи.
Метод WriteToFile записывает JSON-структуру в указанный файл.
Для примера на Fore.NET добавьте ссылки на системные сборки: ForeSystem, WinForms.Utils.
Sub UserProc;
Var
NewJSON: IJsonObjectBuilder;
Doc: IJsonDocument;
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);
// Сохранение в файл
Doc := New JsonDocument.Create;
Doc.Root := NewJSON.Build;
Doc.WriteToFile("d:\Work\Json\testfile.json");
End Sub UserProc;
Imports Prognoz.Platform.Interop.ForeSystem;
Imports Prognoz.Platform.PiLibNet.Utils;
Public Shared Sub Main(Params: StartParams);
Var
NewJSON: IJsonObjectBuilder = ComCreator.Instance.CoCreate<JsonObjectBuilderClass>();
Doc: IJsonDocument = ComCreator.Instance.CoCreate<JsonDocumentClass>();
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);
// Сохранение в файл
Doc.Root := NewJSON.Build();
Doc.WriteToFile("d:\Work\Json\testfile.json", JsonFormatOptions.jfoDefault);
End Sub;
При выполнении примера будет создана новая JSON-структура с некоторым набором элементов. Структура будет сохранена в указанный файл.
См. также: