#1 2015-10-29 01:48:06

dollee
Member
Registered: 2012-08-01
Posts: 3

UTF8 problem on TJSONWriter

my code is

program UTF8Test;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  SynCommons;

var
  AJSON: TJSONWriter;
  AUTF8Text,
  AUTF8Result: RawUTF8;
begin
  try
     AJSON := TJSONWriter.CreateOwnedStream;
     try
        AUTF8Text := '한글(Korean), 日本語(Japanese) Test';
        AJSON.Add('{');
        AJSON.AddFieldName('utf8');
        AJSON.AddJSONEscape(Pointer(AUTF8Text));
        AJSON.Add('}');

        AUTF8Result := AJSON.Text;
     finally
        AJSON.Free;
     end;

     Writeln(AUTF8Result);
     Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

result:

{"utf8":﨑懋ク'#$80'(Korean), 譌・譛ャ隱・Japanese) Test}

how can i do?

Offline

#2 2015-10-29 16:49:58

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,242
Website

Re: UTF8 problem on TJSONWriter

Use stringtoutf8() over the string constant.

Offline

Board footer

Powered by FluxBB