P
Peter Judge
Guest
The OE JSON objects will convert to and from ABL primitives (date, datetime, datetime-tz) from JSON strings and nulls. The strings must use (as noted elsewhere) be formatted per the ISOL 8601 standard. You can use the GetType() method to check what type the JSON is, but the only way to convert to an ABL date/time/tz is to do the Get*() with no-error or a catch block. There are no TryGet()or GetAblType() methods on the built-in JSON objects. The example below shows some examples. using Progress.Json.ObjectModel.JsonObject. def var oj as JsonObject. def var lc as longchar . def var d1 as date . def var d2 as date . def var dt1 as datetime . def var dt2 as datetime-tz . oj = new JsonObject(). oj: add ( 'date' , today ). oj: add ( 'notadate' , 'abcdefg' ). oj: add ( 'datetime' , datetime ( today , mtime )). oj: add ( 'datetime-tz' , datetime-tz ( now )). oj: write ( input-output lc ). d1 = oj:getdate( 'date' ). //d2 = oj:getdate('notadate'). dt1 = oj:getdatetime( 'datetime' ). dt2 = oj:getdatetimetz( 'datetime-tz' ). message string ( lc ) skip ( 2 ) oj:getType( 'date' ) skip //Progress.Json.ObjectModel.JsonDataType:STRING oj:getType( 'notadate' ) skip //Progress.Json.ObjectModel.JsonDataType:STRING d1 skip oj:getType( 'datetime' ) skip dt1 skip oj:getType( 'datetime-tz' ) skip dt2 view-as alert-box . If you try to read a date from a character field that’s not date/time/tx-formatted you get something like --------------------------- Error (Press HELP to view stack trace) --------------------------- ** Invalid date input. (85) --------------------------- OK Help ---------------------------
Continue reading...
Continue reading...