Description
Gets the JSON string data.
Applies to
Syntax
objectname.GetJsonString ( )
Argument |
Description |
---|---|
objectname |
The name of the JSONGenerator or JSONPackage object whose data you want to obtain. |
Return value
String.
Returns the JSON string data if it succeeds and empty string ("") if an error occurs.
Example 1
This example gets the JSON string data: The result is {"object":{"year":2017,"date":"2017-09-21","time":"12:00:00"},"array":[101,102,103]}.
Long ll_RootObject, ll_ChildObject, ll_ChildArray JsonGenerator lnv_JsonGenerator string ls_Json lnv_JsonGenerator = create JsonGenerator // Create an object root item ll_RootObject = lnv_JsonGenerator.CreateJsonObject () // Add an Object child item ll_ChildObject = lnv_JsonGenerator.AddItemObject(ll_RootObject, "object") lnv_JsonGenerator.AddItemNumber(ll_ChildObject, "year", 2017) lnv_JsonGenerator.AddItemDate(ll_ChildObject, "date", 2017-09-21) lnv_JsonGenerator.AddItemTime(ll_ChildObject, "time", 12:00:00) // Add an array child item ll_ChildArray = lnv_JsonGenerator.AddItemArray(ll_RootObject, "array") lnv_JsonGenerator.AddItemNumber(ll_ChildArray, 101) lnv_JsonGenerator.AddItemNumber(ll_ChildArray, 102) lnv_JsonGenerator.AddItemNumber(ll_ChildArray, 103) // Gets the JSON string ls_Json = lnv_JsonGenerator.GetJsonString()
Example 2
This example gets the JSON string data: The result is [{"year":2017,"date":"2017-09-21","time":"12:00:00"},[101,102,103]].
Long ll_RootArray, ll_ChildObject, ll_ChildArray JsonGenerator lnv_JsonGenerator string ls_Json lnv_JsonGenerator = create JsonGenerator // Create an array root item ll_RootArray = lnv_JsonGenerator.CreateJsonArray() // Add an Object child item ll_ChildObject = lnv_JsonGenerator.AddItemObject(ll_RootArray) lnv_JsonGenerator.AddItemNumber(ll_ChildObject, "year", 2017) lnv_JsonGenerator.AddItemDate(ll_ChildObject, "date", 2017-09-21) lnv_JsonGenerator.AddItemTime(ll_ChildObject, "time", 12:00:00) // Add an array child item ll_ChildArray = lnv_JsonGenerator.AddItemArray(ll_RootArray) lnv_JsonGenerator.AddItemNumber(ll_ChildArray, 101) lnv_JsonGenerator.AddItemNumber(ll_ChildArray, 102) lnv_JsonGenerator.AddItemNumber(ll_ChildArray, 103) // Gets the JSON string ls_Json = lnv_JsonGenerator.GetJsonString()
Example 3
This example packages the data of DataWindow, DataStore and DataWindowChild object and assigns the value to a string.
string ls_json 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) ls_json = lnv_package.GetJsonString()
See also