I\'m having trouble converting a string with escaped characters to and from a TJsonString. (I\'m using Delphi XE 2, Update 4, Hotfix 1).
I ran into the same problem with Delphi XE2. My solution was to alter the library file Data.DBXJSON.pas. I copied the original file to my PatchedLibraryXE2 directory (who's first in my library path). Here I changed the method
function TJSONString.ToString: UnicodeString;
begin
if FStrBuffer <> nil then
// Exit('"' + AnsiReplaceStr(FStrBuffer.ToString, '"', '\"') + '"');
Exit('"' + EscapeValue(FStrBuffer.ToString) + '"');
Result := NullString;
end;
I used the escape method of Linas in his answer above. I left out the escape of characters bigger than 127. To compile I also needed to copy the file Data.DBXCommon.pas to my PatchedLibraryXE2 directory. Now my TJSONObject.ToString()
works as expected.