You are not logged in.
The method AddValue of the TDocVariant object displays Chinese garbled characters when adding a Chinese string
I will write a simple program
version 1.18
procedure TForm1.Button1Click(Sender: TObject);
var
lItem: TDocVariantData;
begin
lItem.InitFast;
lItem.AddValue('Caption','哪个数据库');
end;
in debugger the lItem value is :
(271, [dvoIsObject,dvoReturnNullForUnknownProperty,dvoValueCopiedByReference], ('Caption', '', '', ''), ('鍝釜鏁版嵁搴'#$93, Unassigned, Unassigned, Unassigned), 1)
would you help me
Offline
Which compiler do you use?
The string value is passed as a variant.
Depending on the compiler version, it may be encoded differently - and unexpectedly.
Normally, the variant value within the TDocVariantData is encoded as varString and with UTF-8 encoding, which seems the case.
What does Item.ToJson or Item.S['Caption'] respond? I guess it is the correct value.
Don't trust the debugger, it displays something unexpected for you, but something correct for the process itself.
Some other ideas:
- write Item.AddValue('Caption', RawUTF8ToVariant('...'));
- write Item._S['Caption'] := '...';
- write Item.AddValueFromText() and a RawUtf8 content,
- write Item.AddNameValuesToObject(['Caption', '...']); or even InitObject(['Caption, '...']);
Offline
Thank you for your reply
Embarcadero Delphi for Win64 compiler version 35.0
You're right, just garbled in the debugger and placed it in a string variable, that's correct.
Offline
I have added the dvoValueDoNotNormalizeAsRawUtf8 option.
https://github.com/synopse/mORMot2/commit/59f17dfb
It will store the value as it was, without any temporary RawUtf8 conversion.
It may help in your case, if you mostly stay at VCL level.
But if you use it for JSON, then this option is not really needed.
Offline