ImportRowFromJson
method (DataWindows)
Description
Inserts a data row from a JSON string into a DataWindow control,
DataStore object, or DataWindowChild object. The status of the inserted
data row is NotModified!.
The JSON string that can be imported by this function must be a
one-level plain JSON string. For details, see Plain JSON:
one-level structure in Application Techniques.
This function will fail to import data properly, if the DataWindow
is in query mode.
Applies to
|
DataWindow type |
Method applies to |
|---|---|
|
PowerBuilder |
DataWindow control, DataWindowChild object, and |
Syntax
PowerBuilder
|
1 |
long dwcontrol.ImportRowFromJson( string json, long row {, ref string error} {, DWBuffer dwbuffer}) |
|
Argument |
Description |
|---|---|
|
dwcontrol |
A reference to a DataWindow control, DataStore, or |
|
json |
A string specifying the JSON data. The JSON string |
|
row |
A long value identifying the row before which you |
|
error (optional) |
A variable into which the returned warning or error When there are a large amount The import warning caused by data type The import error caused by DW presentation Most of the messages |
|
dwbuffer (optional) |
A value of the dwBuffer enumerated datatype |
Return value
Long. Returns 1 if the data row was added successfully and one of
the following negative integers if an error occurs.
-1 — General error.
-3 — Invalid argument.
-4 — Invalid JSON.
-5 — JSON format error.
-6 — Unsupported DataWindow presentation style for import.
-7 — Error resolving DataWindow nesting.
The method returns null if any of the following:
-
any argument’s value is null
-
the DataWindow object (dataobject) is invalid
Usage
There is no forced conversion between strings and numbers. For
example, the number 123 in JSON string will not be imported into the
DataWindow column of char(10) type. For such case, a data type mismatch
warning will be recorded in the error argument.
A boolean value (true or false) will be converted to 0 or 1 when
imported from the JSON string to the DataWindow; however, 0 or 1 will not
be converted to a boolean value (true or false) when exported from the
DataWindow to the JSON string.
If the string length in JSON is larger than the string length in
DataWindow, the string will be truncated when imported into the
DataWindow. For example, JSON string [{“name”:”TestForTrancate”}] is
imported as “Test” if the data type of DataWindow column “name” is
char(4).
When the number value is imported from the JSON string to the
DataWindow column of number data type (with uncertain precision), the
value will have uncertain decimals, for example, 6.78 becomes
6.78000020980835 after imported from the JSON string to the
DataWindow.
Example
The following example imports two rows, one before the first row and
the other before the last row.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
String ls_Json = '{"dept_id":1900,"dept_name":"Test send patch request42","dept_head_id":"test"}' String ls_Error Integer li_ImportJsonReturn //Inserts a row before the first row //Note that the column name and data type between JSON string and DataWindow must match li_ImportJsonReturn = dw_Data.ImportRowFromJson( ls_Json, 1, ls_Error) If Trim(ls_Error) <> "" Then //Prints the value of ls_Error. //The data type of the last column between JSON string and DataWindow does not match //so there will be an error message here. End If ls_Json = '{"dept_id":1900,"dept_name":"Test send patch request42","dept_head_id":1}' //Inserts a row before the last row //Note that the column name and data type between JSON string and DataWindow must match li_ImportJsonReturn = dw_Data.ImportRowFromJson( ls_Json, 0, ls_Error, Primary!) If Trim(ls_Error) <> "" Then //Prints the value of ls_Error End If |
See also