LoadString

Description

Loads a JSON string. The JSON string that can be loaded by the JSONPackage object must be an object (cannot be an array) and the value can be any valid string, object, or array. See JSON format for details.

Applies to

JSONParser and JSONPackage objects

Syntax

objectname.LoadString ( JsonData )

Argument

Description

objectname

The name of the JSONParser or JSONPackage object to which the JSON string will be loaded.

JsonData

A string whose value is the JSON data of JsonObjectItem type.


Return value

String.

Returns the empty string ("") if it succeeds and the error message if an error occurs. If any argument's value is null, the method returns null.

Examples

This example loads a JSON string into the JSONParser object:

String ls_Error
JsonParser lnv_JsonParser 
lnv_JsonParser = Create JsonParser

String ls_Json = '{"id":1, "name":"evan1", "birthday":2340323884}'
ls_Error = lnv_JsonParser.LoadString(ls_Json)
if Len(ls_Error) > 0 then
 MessageBox("Error", ls_Error)
end if

This example gets the data from the server and then loads the "d_employee" data to the DataWindow:

int li_rc
string ls_JsonPackage, ls_Error, ls_EmployeeJson
HttpClient lnv_HttpClient
JsonPackage lnv_package

lnv_HttpClient = create HttpClient
lnv_package = create JsonPackage

// Request the JSON data package from server
li_rc = lnv_HttpClient.SendRequest("GET", "http://demo.appeon.com/PB/webapi_client/employee/102")

// Get the data
if li_rc = 1 and lnv_HttpClient.GetResponseStatusCode() = 200 then
	lnv_HttpClient.GetResponseBody(ls_JsonPackage)
	// Extract the JSON data package
	ls_Error = lnv_package.LoadString(ls_JsonPackage)
	if Len(ls_Error) = 0 then
		ls_EmployeeJson = lnv_package.GetValue("d_employee")
		dw_1.ImportJson(ls_EmployeeJson)
	else
		Messagebox("Error", ls_Error)
	end if
end if

See also

LoadFile

JSON formats (required by JSONPackage object)

The JSON string that can be loaded by the JSONPackage object must be an object (cannot be an array) and the item must be a string, object or array. For example,

{
"d_department": {"department_id":1, "name": "developer"},
"d_employee": [{"empoyee_id":1, "name": "my name1"}, {"empoyee_id":2, "name": "my name2"}],
"d_employee_syntax": "release 17;\r\n datawindow(units=0 timer_interval=0 color=1073741824..."
}