SaveToFile

Description

Saves the JSON data to the local file.

Applies to

JSONGenerator and JSONPackage objects

Syntax

objectname.SaveToFile ( FileName )

Argument

Description

objectname

The name of the JSONGenerator or JSONPackage object whose data you want to save to the file.

FileName

A string whose value is the file full name.


Return value

Integer.

Returns 1 if it succeeds and -1 if an error occurs. If any argument's value is null, the method returns null.

Examples

This example generates the following JSON string and saves to d:\test.json:

{ "string": "string", "long": 100, "boolean": true, "datetime": "2017-09-21 12:00:00", "blob": "dABoAGkAcwAgAGkAcwAgAGIAbABvAGIA", "remark": null }

Long ll_RootObject
JsonGenerator lnv_JsonGenerator
lnv_JsonGenerator = Create JsonGenerator

// Create an object root item
ll_RootObject = lnv_JsonGenerator.CreateJsonObject()

// Add a value child item
lnv_JsonGenerator.AddItemString(ll_RootObject, "string", "string")
lnv_JsonGenerator.AddItemNumber(ll_RootObject, "long", 100)
lnv_JsonGenerator.AddItemBoolean(ll_RootObject, "boolean", true)
lnv_JsonGenerator.AddItemDateTime(ll_RootObject, "datetime", datetime("2017-09-21 12:00:00")) 
lnv_JsonGenerator.AddItemBlob(ll_RootObject, "blob", blob("this is blob"))
lnv_JsonGenerator.AddItemNull(ll_RootObject, "remark")

// Get the JSON data
lnv_JsonGenerator.SaveToFile("d:\test.json")

This example packages the data of the DataWindow, DataStore, and DataWindowChild control and then saves the data to D:\temp\json.txt.

datastore lds_employee
datawindowchild ldwc_active
JsonPackage lnv_package
lnv_package = create JsonPackage

...//Initialize data for lds_employee, ldwc_active

// package the data
lnv_package.SetValue("d_department", dw_department, false)
lnv_package.SetValue("d_employee", lds_employee) 
lnv_package.SetValue("dddw_active", ldwc_active, false)
lnv_package.SaveToFile("D:\temp\json.txt")