Description
Loads a JSON string to the JSONParser or JSONPackage objects.
Applies to
Required JSON format
-
For JSONParser object: The string that can be loaded by the JSONParser object must be JSON-formatted.
-
For JSONPackage object: The file content that can be loaded by the JSONPackage object must be an object which contains a set of key/value pairs where key is the name of a JSONObjectItem-type object (corresponding to the data being added into the package, such as "d_department" and "d_employee_syntax") and the value for the key can be a string, object, or array in the following formats: plain JSON, or DataWindow JSON.
Here is the structure of this JSON format:
{ "KEY1":VALUE1, "KEY2":VALUE2, "KEY3":VALUE3… }
Here is an example of this JSON format:
{ "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..." }
Syntax
objectname.LoadString ( JsonData )
Argument |
Description |
---|---|
objectname |
The name of the JSONParser or JSONPackage object to which the JSON string will be loaded. |
JsonData |
(For JSONParser object) A JSON-formatted string. (For JSONPackage object) 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", "https://demo.appeon.com/PB/webapi_client/getjsonpackage/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