GetValueToDataWindow
Description
Gets the value of the key and inserts it into a DataWindow control,
DataStore object, or DataWindowChild object.
If more than one key with the same name exists, then get the value
of the first key. Notice that the IgnoreCase property (true by default)
determines whether the key name will be matched in a case-sensitive
manner.
This function will fail to import data properly, if the DataWindow
is in query mode.
Applies to
Syntax
|
1 |
objectname.GetValueToDataWindow (string key, dwcontrol DWControl {, boolean resetflag} {, string error} {, DWBuffer dwbuffer {, long startrow {, long endrow } } } ) |
|
Argument |
Description |
|---|---|
|
objectname |
The name of the JSONPackage object |
|
Key |
A string specifying the key of the item of JsonStringItem |
|
dwcontrol |
A reference to a DataWindow control, DataStore, or |
|
resetflag (optional) |
A boolean value specifying whether dwcontrol should |
|
error (optional) |
A variable into which the returned warning or error When there are a large amount of error messages, the error The import warning caused by data type mismatch will not The import error caused by DW presentation style mismatch, Most of the messages placed into this variable are |
|
dwbuffer (optional) |
A value of the dwBuffer enumerated datatype identifying For plain JSON: If not specified, imports the JSON data to For DataWindow JSON: If not specified, imports data of all |
|
startrow (optional) |
The number of the first detail object in the JSON Array |
|
endrow (optional) |
The number of the last detail object in the JSON Array |
Return value
Long. Returns the number of rows that were imported if it succeeds
and one of the following negative integers if an error occurs. The return
value will count the rows imported into the primary, filter, and delete
buffers, but not the rows imported into DataWindowChild.
0 — When all of the data in the JSON string is null, or the JSON
string only contains data for DataWindowChild, or no JSON key matches with
the DataWindow column.
-1 — General error.
-2 — No row is supplied or the startrow value supplied is greater
than the number of rows in the JSON data.
-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” when 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 1
This example obtains the key value from the JSON string and sets the
value to DataWindow.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
// long GetValueToDataWindow ( string key, dwcontrol DWControl ) Integer li_Return JsonPackage ljpk_Dept ljpk_Dept = Create JsonPackage // The DataWindow column name and type must match with that in the JSON string dw_Dept.DataObject = "d_example_dept" // Loads the DataWindow JSON string to the JsonPackage object ljpk_Dept.LoadString('{"name":"Powerbuilder", "dept":{"identity":"70c86603-983b-4bd9-adbc-259436e43cbd", "version":1, "platform":"PowerBuilder", "mapping-method":0, "dataobject":{"name":"d_example_dept", "meta-columns":[{"name":"dept_id", "index":0, "datatype":"long", "nullable":1}, {"name":"dept_name", "index":1, "datatype":"string", "nullable":1}, {"name":"dept_head_id", "index":2, "datatype":"long", "nullable":1}], "primary-rows":[{"row-status":0, "columns":{"dept_id":[100], "dept_name":["R & D8"], "dept_head_id":[105]}}, {"row-status":0, "columns":{"dept_id":[200], "dept_name":["Sales"], "dept_head_id":[129]}}, {"row-status":0, "columns":{"dept_id":[300], "dept_name":["Finance"], "dept_head_id":[102]}}, {"row-status":0, "columns":{"dept_id":[400], "dept_name":["Marketing"], "dept_head_id":[1576]}}, {"row-status":0, "columns":{"dept_id":[500], "dept_name":["Shipping"], "dept_head_id":[703]}}, {"row-status":0, "columns":{"dept_id":[999], "dept_name":["test4"], "dept_head_id":[null]}}]}}}') // Loads the data from the JSON string to DataWindow li_Return = ljpk_Dept.GetValueToDatawindow ("dept", dw_Dept) If li_Return <= 0 Then // Prints the error message End If // Loads the plain JSON string to the JsonPackage object ljpk_Dept.LoadString('{"dept2":[{"dept_id":100, "dept_name":"R & D8", "dept_head_id":105}, {"dept_id":200, "dept_name":"Sales", "dept_head_id":129}, {"dept_id":300, "dept_name":"Finance", "dept_head_id":102}, {"dept_id":400, "dept_name":"Marketing", "dept_head_id":1576}, {"dept_id":500, "dept_name":"Shipping", "dept_head_id":703}]}') // Loads the data from the JSON string to DataWindow li_Return = ljpk_Dept.GetValueToDatawindow ("dept2", dw_Dept) If li_Return <= 0 Then // Prints the error message End If |
Example 2
This example obtains the data in rows 2 through 4 from the JSON
string and sets the data to DataWindow.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// long GetValueToDataWindow ( string key, dwcontrol DWControl, boolean resetflag, DWBuffer dwbuffer, long startrow, long endrow ) Integer li_Return JsonPackage ljpk_Dept ljpk_Dept = Create JsonPackage // The DataWindow column name and type must match with that in the JSON string dw_Dept.DataObject = "d_example_dept" ljpk_Dept.LoadString('{"dept":[{"dept_id":100, "dept_name":"R & D8", "dept_head_id":105}, {"dept_id":200, "dept_name":"Sales", "dept_head_id":129}, {"dept_id":300, "dept_name":"Finance", "dept_head_id":102}, {"dept_id":400, "dept_name":"Marketing", "dept_head_id":1576}, {"dept_id":500, "dept_name":"Shipping", "dept_head_id":703}]}') // Loads the data from the JSON string to DataWindow: startrow:2, endrow:4. // GetValueToDataWindow returns 3, indicating 3 rows have been imported. li_Return = ljpk_Dept.GetValueToDataWindow("dept", dw_Dept, False, Filter!, 2, 4 ) dw_Dept.SetFilter("") // Displays the data imported to the Filter buffer dw_Dept.Filter() |
Example 3
This example obtains the key value from the JSON string and imports
the value to the specified DataWindow buffer.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
// long GetValueToDataWindow ( string key, dwcontrol DWControl, string error, DWBuffer dwbuffer ) Integer li_Return String ls_Error JsonPackage ljpk_Dept ljpk_Dept = Create JsonPackage // The DataWindow column name and type must match with that in the JSON string dw_Dept.DataObject = "d_example_dept" ljpk_Dept.LoadString('{"dept1":[{"dept_id":500,"dept_name":"Shipping","dept_head_id":703}],"dept2":[{"dept_id":"100","dept_name":"R & D8","dept_head_id":"test"}]}') // 105 // Loads the data of dept1 from the JSON string to DataWindow li_Return = ljpk_Dept.GetValueToDataWindow("dept1", dw_Dept, ls_Error, Primary! ) // Prints ls_error. It is an empty string. // Loads the data of dept2 from the JSON string. // The value type in the JSON string does not match with that in the DataWindow. Error is saved to ls_Error. li_Return = ljpk_Dept.GetValueToDataWindow("dept2", dw_Dept, ls_Error, Primary! ) // Prints ls_Error. // Total errors: 2 // Row 1, node "dept_id" in the JSON object has a different data type from column 1 in the Primary buffer. // Row 1, node "dept_head_id" in the JSON object has a different data type from column 3 in the Primary buffer. |
See also