SetValueDateTime
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
|
1 |
objectname.SetValueDateTime ( Key, Value ) |
|
1 |
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 True — JsonNumberItem type. A JsonNumberItem type value False — JsonStringItem type. A JsonStringItem type value |
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.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// 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