Description

The RTI_JSON 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.

Syntax

RTI_JSON(handle, action, param1, param2, param3)

Parameters

The function has the following parameters:

ParameterDescription
Action = Parse:Handle: variable that will hold the created javascript or JSON object

Param1: the javascript function or JSON expression Return value: 0 if successful, or OLE error code

Action = 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

Action = 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 Param3: “1” if the value represents an object rather than a simple string Return value: 0 if successful, or OLE error code

Action = Stringify:Handle: the variable that contains the previously-created javascript or JSON object

Return value: the string representation of the JSON object

Action = 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

Action = GetMethods:Handle: the variable that contains the previously-created javascript or JSON object

Return value: @VM delimited list of the methods of the javascript or JSON object

Action = Eval:Handle: unused, pass in empty string (“”)

Param1: javascript source or JSON string Return value: the evaluated object

Action = 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 Return value: the evaluated variable object

 

Example 1

myObject = RTI_JSON('', 'New', 'OBJECT')  ; * generic object
myNumber = RTI_JSON('', 'New', 'Number', '21')
myString = RTI_JSON('', 'New', 'String', 'Hello World')
myBool   = RTI_JSON('', 'New', 'Boolean', '1')
mydate   = RTI_JSON('', 'New', 'Date', date(), time())  ; * javascript date object
myRegEx  = RTI_JSON('', 'New', 'REGEXP', "\bt[a-z]+\b") ; * regular expression
myArray  = RTI_JSON('', 'New', 'ARRAY', '"A","B","C"')
x = Rti_JSON(MyArray, 'SetValue', '[3]', 'D')
v1 = Rti_JSON(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_JSON( jString, 'Parse')
table = RTI_JSON(oRec, 'GetValue', "rti_table")  ;* should return BOOKS
If table = '' Then
   Return ''
End
id  = RTI_JSON(oRec, 'GetValue', "id") ;* should return 1021

Example 3

myGrid = rti_json('','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<i,1>
  val = list<i,2>
  if item # '' then
     obj = rti_json('','New', 'STRING', val)   ;* create a new string object for each value
     x = rti_json(myGrid, 'SetObject', '[':k:']', obj, 1) ;* store it into the array
     k+=1
  end  
next 
myobj = rti_json('','New', 'OBJECT') ;* create a new empty object
x = rti_json(myobj,'SetObject', 'myGrid', myGrid, 1) ;* put the previously-created grid into the object
JString = rti_json(myobj, "Stringify") ;* return the JSON string
  • No labels