====== RTI_JSON9 Function ======
==== Description ====
The RTI_JSON9 function allows you to evaluate either a javascript function or a JSON (JavaScript Object Notation) expression. After passing in a javascript function or a JSON expression, you can invoke the function or evaluate the expression, and retrieve results.
**Note:** RTI_JSON9 uses a javascript implementation of the JSON parser. In OpenInsight 10 by default, RTI_JSON uses an open source library (rapidJSON).
==== Syntax ====
RTI_JSON9(handle, action, param1, param2, param3)
==== Parameters ====
The function has the following parameters:
^Action^Description^
|Parse|Handle: the javascript function or JSON expression\\ \\ Return value: the handle to use for subsequent RTI_JSON9 calls if successful, or 0 if unsuccessful|
|New|Handle: unused, pass in empty string (“”)\\ \\ Param1: the type of variable to create. Valid types include “OBJECT” (for a generic object), “NUMBER”, “STRING”, “BOOLEAN”, “DATE”, “REGEXP”, and “ARRAY”\\ \\ Param2: the initial value of the created variable\\ \\ Param3: the optional time value for a DATE, or the optional flags for a REGEXP\\ \\ Return value: the evaluated variable object|
|Stringify|Handle: the variable that contains the previously-created javascript or JSON object\\ \\ Return value: the string representation of the JSON object|
|GetValue|Handle: the variable that contains the previously-created javascript or JSON object\\ \\ Param1: the name of the variable whose value should be retrieved. This can be an array element (enclosed in square braces, ie, “[1]”) if accessing an array object.\\ \\ Return value: the specified variable’s value|
|SetValue|Handle: the variable that contains the previously-created javascript or JSON object\\ \\ Param1: the name of the variable whose value should be set. This can be an array element (enclosed in square braces, ie, “[1]”) if accessing an array object.\\ \\ Param2: the value to which the variable should be set\\ \\ Return value: 0 if successful, or OLE error code|
|GetObject|Handle: the variable that contains the previously-created javascript or JSON object\\ \\ Param1: the name of the variable to extract\\ \\ Return value: the handle of the extracted object to use for subsequent RTI_JSON9 calls|
|SetObject|Handle: the variable that contains the previously-created javascript or JSON object\\ \\ Param1: the name of the element to update\\ \\ Param2: the variable that contains the previously-created JSON object to insert\\ \\ Return value: handle if successful, or null otherwise|
|isObject|Handle: the element to examine\\ \\ Return value: '1' if the element is an object or '0' otherwise|
|GetProperties|Handle: the variable that contains the previously-created javascript or JSON object\\ \\ Return value: @VM delimited list of the properties of the javascript or JSON object|
|GetLength|Handle: the variable that contains the previously-created javascript or JSON object\\ \\ Param1: the name of the element to evaluate\\ \\ Return value: the length of the specified element|
|Eval|Handle: unused, pass in empty string (“”)\\ \\ Param1: javascript source or JSON string\\ \\ Return value: the evaluated object|
|DeleteItem\\ DeleteObject|Handle: the variable that contains the previously-created javascript or JSON object\\ \\ Param1: the name of the element to delete\\ \\ Return value: '1' if successful, '0' otherwise|
|Refresh|Handle: unused\\ \\ Param1: unused\\ \\ Return value: none|
==== Returns ====
==== Remarks ====
==== See Also ====
==== Example ====
Example 1:
myObject = RTI_JSON9('', 'New', 'OBJECT') ; * generic object
myNumber = RTI_JSON9('', 'New', 'Number', '21')
myString = RTI_JSON9('', 'New', 'String', 'Hello World')
myBool = RTI_JSON9('', 'New', 'Boolean', '1')
mydate = RTI_JSON9('', 'New', 'Date', date(), time()) ; * javascript date object
myRegEx = RTI_JSON9('', 'New', 'REGEXP', "\bt[a-z]+\b") ; * regular expression
myArray = RTI_JSON9('', 'New', 'ARRAY', '"A","B","C"')
x = Rti_JSON9(MyArray, 'SetValue', '[3]', 'D')
v1 = Rti_JSON9(MyArray, 'GetValue', '[0]') ;* v1 should now contain “A”
Example 2:
* given the following JSON string:
* { "rti_table":"BOOKS", "id":"1021","BOOK_ID":"1021","TITLE":"China%20and%20the%20Manchus","AUTHOR":"Herbert%20A.%20Giles",
"CHECK_OUT_DATE":"","RESERVED_BY":"","COMMENTS":"","CHECKED_OUT_BY":"","LAST_UPDATE_BY":"","LAST_UPDATE_DATE":"",
"COVER_IMAGE":"","ISBN":"","BLERT":"","TM":"","COLUMN_13":"","COLUMN_14":"","COLUMN_15":"","COLUMN_16":"","COLUMN_17":"",
"COLUMN_18":"","EMAIL_ADDRESS":"","PICTURE":"","DC":"E","ZZ1":"567","LISS":"","JW":"","COLUMN_25":"","COLUMN_26":"",
"COLUMN_27":"","IS_AVAILABLE":"","COLUMN_29":"","DATETIMEWRITTEN":""}
oRec = RTI_JSON9( jString, 'Parse')
table = RTI_JSON9(oRec, 'GetValue', "rti_table") ;* should return BOOKS
If table = '' Then
Return ''
End
id = RTI_JSON9(oRec, 'GetValue', "id") ;* should return 1021
Example 3:
myGrid = rti_json9('','New', 'ARRAY') ;* create a new, empty array object
list = Get_Property(@window:'.GRID', 'LIST') ;* get the elements of a list
cnt = count(list, @fm) + ( list # '' )
k = 0
for i = 1 to cnt
item = list
val = list
if item # '' then
obj = rti_json9('','New', 'STRING', val) ;* create a new string object for each value
x = rti_json9(myGrid, 'SetObject', '[':k:']', obj, 1) ;* store it into the array
k+=1
end
next
myobj = rti_json9('','New', 'OBJECT') ;* create a new empty object
x = rti_json9(myobj,'SetObject', 'myGrid', myGrid, 1) ;* put the previously-created grid into the object
JString = rti_json9(myobj, "Stringify") ;* return the JSON string