Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-11

JSon stream to unicode?

8 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Leonardo M. Ramé

Hi, I'm receiving from a Delphi 7 app a unicode Stream (from Synapse library) containing Unicode data and I need to show it in a Lazarus form. How can I convert it to look correctly on screen?.

Example:

The string "Leonardo Ram?" is shown as "Leonardo Ram\u009".

Reply by email

Michael Van Canneyt
to Leonardo M. Ramé
Leonardo M. Ram? wrote 7 lines
Hi, I'm receiving from a Delphi 7 app a unicode Stream (from Synapse library) containing Unicode data and I need to show it in a Lazarus form. How can I convert it to look correctly on screen?. Example: The string "Leonardo Ram?" is shown as "Leonardo Ram\u009".

If you're using the fpJSON unit, it's currently not UTF-8 tested. It *should* work - insofar that unicode escape sequences are recognized and converted. I've never tested that, though.

Also, if you're on linux, make sure you're using the cwstrings unit.

Michael.

Reply by email

Lee Jenkins

SuperObject works in both Delphi and fpc. Google superobject json to find the website.

Lee

"Leonardo M. Ram?" wrote 17 lines
Hi, I'm receiving from a Delphi 7 app a unicode Stream (from Synapse library) containing Unicode data and I need to show it in a Lazarus form. How can I convert it to look correctly on screen?. Example: The string "Leonardo Ram?" is shown as "Leonardo Ram\u009". -- Leonardo M. Ram? http://leonardorame.blogspot.com -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Leonardo M. Ramé
to Michael Van Canneyt: If you're using the fpJSON unit, it's currently not UTF-8 tested. It *should* work -…
Michael Van Canneyt wrote 19 lines
On Fri, 12 Nov 2010, Leonardo M. Ram? wrote: >Hi, I'm receiving from a Delphi 7 app a unicode Stream (from Synapse >library) containing Unicode data and I need to show it in a Lazarus >form. How can I convert it to look correctly on screen?. > >Example: > >The string "Leonardo Ram?" is shown as "Leonardo Ram\u009". If you're using the fpJSON unit, it's currently not UTF-8 tested. It *should* work - insofar that unicode escape sequences are recognized and converted. I've never tested that, though. Also, if you're on linux, make sure you're using the cwstrings unit. Michael.

I'm usin fpJSON on Windows. I'll test it a little more next week.

Reply by email

Michael Fuchs
to Leonardo M. Ramé: Hi, I'm receiving from a Delphi 7 app a unicode Stream (from Synapse library) containing…
Show quoted text 8 lines
Hi, I'm receiving from a Delphi 7 app a unicode Stream (from Synapse library) containing Unicode data and I need to show it in a Lazarus form. How can I convert it to look correctly on screen?. Example: The string "Leonardo Ram?" is shown as "Leonardo Ram\u009".

I had the same problem and use now the following function for decoding:

function DecodeUnicodeEscapes(EscapedString: String): String;
var
  FoundPos: LongInt;
  HexCode: String;
  DecodedChars: String;
begin
  Result := EscapedString;
  FoundPos := Pos('\u', Result);
  while (FoundPos  0) and (FoundPos < Length(Result) - 4) do begin
    HexCode :=  Copy(Result, FoundPos + 2, 4);
    DecodedChars := WideChar(Hex2Dec(HexCode));
    Result := AnsiReplaceStr(Result, '\u' + HexCode,
                             UTF8Encode(DecodedChars));
    FoundPos := Pos('\u', Result);
  end;
end;

hth
Michael

Reply by email

Leonardo M. Ramé
to Michael Fuchs
Michael Fuchs wrote 34 lines
Leonardo M. Ram? schrieb: > Hi, I'm receiving from a Delphi 7 app a unicode Stream (from Synapse > library) containing Unicode data and I need to show it in a Lazarus > form. How can I convert it to look correctly on screen?. > > Example: > > The string "Leonardo Ram?" is shown as "Leonardo Ram\u009". > I had the same problem and use now the following function for decoding: function DecodeUnicodeEscapes(EscapedString: String): String; var FoundPos: LongInt; HexCode: String; DecodedChars: String; begin Result := EscapedString; FoundPos := Pos('\u', Result); while (FoundPos 0) and (FoundPos < Length(Result) - 4) do begin HexCode := Copy(Result, FoundPos + 2, 4); DecodedChars := WideChar(Hex2Dec(HexCode)); Result := AnsiReplaceStr(Result, '\u' + HexCode, UTF8Encode(DecodedChars)); FoundPos := Pos('\u', Result); end; end; hth Michael

Thanks Michael, I'll try that.

Reply by email

Michael Van Canneyt
to Leonardo M. Ramé: I'm usin fpJSON on Windows. I'll test it a little more next week. Leonardo M. Ram?…
Leonardo M. Ram? wrote 22 lines
On 2010-11-12 22:04:06 +0100, Michael Van Canneyt wrote: > > > On Fri, 12 Nov 2010, Leonardo M. Ram? wrote: > >> Hi, I'm receiving from a Delphi 7 app a unicode Stream (from Synapse >> library) containing Unicode data and I need to show it in a Lazarus >> form. How can I convert it to look correctly on screen?. >> >> Example: >> >> The string "Leonardo Ram?" is shown as "Leonardo Ram\u009". > > If you're using the fpJSON unit, it's currently not UTF-8 tested. > It *should* work - insofar that unicode escape sequences are recognized and > converted. I've never tested that, though. > > Also, if you're on linux, make sure you're using the cwstrings unit. > > Michael. I'm usin fpJSON on Windows. I'll test it a little more next week.

If there is anything I can do to help, let me know.

Michael.

Reply by email