Description
Sets the datetime value for a key. If the key does not exist, then create the key and set its value. If the key already exists, then overwrite the value of this key. If more than one key with the same name already exists, then overwrite 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.
Applies to
Syntax
objectname.SetValueDateTime ( Key, Value )
objectname.SetValueDateTime ( Key, Value, Flag )
Argument |
Description |
---|---|
objectname |
The name of the JSONPackage object. |
Key |
A string specifying the key name. |
Value |
A datetime specifying the key value. |
Flag |
A boolean whose value is the type of the child item. True -- JsonNumberItem type. A JsonNumberItem type value is a UTC timestamp converted from the local time using the local timezone. False -- JsonStringItem type. A JsonStringItem type value is a string converted from the local time directly (no timezone conversion). |
Return value
Integer.
Returns 1 if it succeeds and -1 if an error occurs. If any argument's value is null, the method returns null.
Examples
This example sets the value of the birthday key and the createdate key in the JSON string.
// Integer SetValueDateTime (string Key, datetime Value) DateTime ldt_CreateDate,ldt_Birthday JsonPackage ljpk_User ljpk_User = Create JsonPackage // Loads the JSON string to the JSONPackage object ljpk_User.loadstring( '{"id":100,"name":"Henry.Ken","birthday":"1998-12-01 08:02:30","CreateDate":1543900359 }') ljpk_User.SetValueDateTime("birthday", DateTime(Today(), Now())) // This will change the ItemType of the CreateDate key to JsonStringItem! ljpk_User.SetValueDateTime("CreateDate", DateTime(Today(), Now())) // GetValueDateTime can also get a long value or a string value. // It is recommended to check if it is a datetime value, otherwise exception may be thrown. ldt_CreateDate = ljpk_User.GetValueDateTime("CreateDate") ldt_Birthday = ljpk_User.GetValueDateTime("birthday")
See also