Recent

Author Topic: [Solved] Unicode escape sequence \u and fpjson  (Read 1900 times)

Gerard

  • Newbie
  • Posts: 4
[Solved] Unicode escape sequence \u and fpjson
« on: February 25, 2024, 09:54:51 am »
Hi,

I am trying to pick up Pascal again by converting a Python script I wrote to display news items (coming from the Mozilla Pocket API). Having some trouble with Korean text. When having multiple Korean characters often the second character is not displayed. With the simplified example below:

Code: Pascal  [Select][+][-]
  1.      koreanJsonData := GetJSON('{ "example": "Two unicode characters immediately after each other \uadf8\ub8f9 " }' );
  2.      Memo1.Append(koreanJsonData.findpath('example').AsString);
  3.  

It should display: 그룹 (그 geu and 룹 is roup, basically the word 'group' in Korean)
When not having the space a space between the \u sequences it does not display anything at all without any error.With a space it displays the characters above (with a space in between).

I tried a few variations on the above, but cannot get it to display correctly. Probably I am doing something wrong, or am I encountering a bug?

Best regards,
Gerard
« Last Edit: February 27, 2024, 11:50:38 pm by Gerard »

ASerge

  • Hero Member
  • *****
  • Posts: 2340
Re: Unicode escape sequence \u and fpjson
« Reply #1 on: February 25, 2024, 10:00:50 am »
Code: Pascal  [Select][+][-]
  1. koreanJsonData := GetJSON('{ "example": "Two unicode characters immediately after each other '#$adf8#$b8f9' " }');

paweld

  • Hero Member
  • *****
  • Posts: 1268
Re: Unicode escape sequence \u and fpjson
« Reply #2 on: February 25, 2024, 10:29:17 am »
On Lazarus trunk and FPC 3.2-fixes is ok:
Code: [Select]
Two unicode characters immediately after each other 그룹 but if FPC 3.2.2 then:
Code: [Select]
Two unicode characters immediately after each other 그?
Best regards / Pozdrawiam
paweld

Gerard

  • Newbie
  • Posts: 4
Re: Unicode escape sequence \u and fpjson
« Reply #3 on: February 25, 2024, 10:30:35 am »
Thanks, that indeed seems to work with setting a string in code. I might have simplified to much though.

In my complete program I use stringTFPHTTPClient.SimpleGet to get JSON data from the Mozilla Pocket web API. Instead of the string in my example the resulting JSON data from SimpleGet (stored in a string) is the argument for GetJSON().

In that input with multiple \u-characters I get output like this (second character always a question mark): 에?는 최? 국?

I would expect that to be valid JSON-data (the \u escape sequence notation) that should be interpreted by fpjson, right?

Gerard

  • Newbie
  • Posts: 4
Re: Unicode escape sequence \u and fpjson
« Reply #4 on: February 25, 2024, 10:32:29 am »
On Lazarus trunk and FPC 3.2-fixes is ok:
Code: [Select]
Two unicode characters immediately after each other 그룹 but if FPC 3.2.2 then:
Code: [Select]
Two unicode characters immediately after each other 그?

Ah, a bug after all, thanks!

Gerard

  • Newbie
  • Posts: 4
Re: Unicode escape sequence \u and fpjson
« Reply #5 on: February 27, 2024, 09:18:07 pm »
On Lazarus trunk and FPC 3.2-fixes is ok:
Code: [Select]
Two unicode characters immediately after each other 그룹 but if FPC 3.2.2 then:
Code: [Select]
Two unicode characters immediately after each other 그?

It took a while to get FPC 3.2-fixes working with Lazarus. In case somebody else encounters this thread with the same problem, try FPCUPdeluxe, saves a lot of trouble. Unicode \u escape sequences work fine now.
« Last Edit: February 27, 2024, 09:22:44 pm by Gerard »

bird00101011

  • Newbie
  • Posts: 6
Re: [Solved] Unicode escape sequence \u and fpjson
« Reply #6 on: June 24, 2024, 07:58:55 am »
 >:D >:D >:D >:D >:(

 

TinyPortal © 2005-2018