MyChat Scripts Engine: JSONSetString, add a string to a JSON object
Function to update or create a text key in a JSON object.
Syntax
function JSONSetString(var sJSON: string; sKey: string; sValue: string): integer;
Parameters and return values
Parameter |
Type |
Value |
sJSON |
string |
JSON object as a text string; if you set an empty string, the object will be created automatically; |
sKey |
string |
required key name. |
Function result
0 |
no errors; |
1 |
JSON parsing error. |
Example
var
s: string;
begin
s := '{"UserName" : "Jack Nicolson"}';
mLogScript('Before: ' + s, 'TEST')
JSONSetString(s, 'UserName', 'John Smith');
mLogScript('After: ' + s, 'TEST');
end.
Script work result
[18:35:47] (Log "test"): [TEST] Before: {"UserName" : "Jack Nicolson"}
[18:35:47] (Log "test"): [TEST] After: {"UserName":"John Smith"}