Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
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

Code Block
* 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

Code Block
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