System.JSON.Utils.TJsonTextUtils.WriteEscapedString
Delphi
class procedure WriteEscapedString(const Writer: TTextWriter; const Str: string; Delimiter: Char; AppendDelimiters: Boolean; const CharEscapeFlags: array of Boolean; StringEscapeHandling: TJsonStringEscapeHandling; var WriteBuffer: TCharArray);
C++
__classmethod void __fastcall WriteEscapedString(System::Classes::TTextWriter* const Writer, const System::UnicodeString Str, System::WideChar Delimiter, bool AppendDelimiters, bool const *CharEscapeFlags, const int CharEscapeFlags_High, System::Json::Types::TJsonStringEscapeHandling StringEscapeHandling, System::DynamicArray<System::WideChar> &WriteBuffer);
Properties
| Type | Visibility | Source | Unit | Parent |
|---|---|---|---|---|
procedure function |
public | System.JSON.Utils.pas System.JSON.Utils.hpp |
System.JSON.Utils | TJsonTextUtils |
Description
Generates a JSON string from a given string.
WriteEscapedString receives the following parameters:
Writeris the text writer that WriteEscapedString uses to generate the resulting JSON string.Stris the string to convert into a JSON string.AppendDelimitersdetermines whether the resulting string is surrounded by quotation characters (True) or not (False).Delimiteris the quotation character to add both at the beginning and at the end of the resulting JSON string ifAppendDelimitersisTrue. For the resulting JSON string to be a proper JSON string, this character must be either a single quote (') or a double quote (").CharEscapeFlagsis an array of character escaping flags. For more information, see Character Escaping below.StringEscapeHandlingdetermines the type of character escaping that WriteEscapedString uses.WriteBufferis a buffer that WriteEscapedString uses internally.
Character Escaping
WriteEscapedString escapes:
- Characters that have a
Trueflag inCharEscapeFlags. - Characters that do not have a matching flag in
CharEscapeFlags, ifStringEscapeHandlingis TJsonStringEscapeHandling.EscapeNonAscii.
WriteEscapedString escapes most characters using Unicode escaping sequences. The following table shows the only characters that WriteEscapedString escapes differently:
| Character | Escaped Character |
|---|---|
|
Tab |
|
|
New line |
|
|
Carriage return |
|
|
Form feed |
|
|
Backspace |
|
|
Backslash |
|
|
Double quote* |
|
|
Single quote* |
|
- * If
StringEscapeHandlingis TJsonStringEscapeHandling.EscapeHtml, WriteEscapedString escapes single quotes and double quotes using Unicode escaping sequences.