Thanks all, Sven solution works. Yes this is not JSON it's some kind of JSON-like format (Is it yml ? I don't know it might be proprietary). I was naive and thought there was some metadata in files precising the encoding used, and that #readStream on FileReference was able to pick automatically the correct decoder. Obviously it isn't the case. Thanks anyway. 2018-01-29 18:59 GMT+01:00 Sven Van Caekenberghe <sven@stfx.eu>:
Your file is not in UTF-8 but in UTF-16 !
This will do:
(FileLocator desktop / 'schinese.txt') readStreamDo: [ :in | (ZnCharacterReadStream on: in binary encoding: #utf16) upToEnd ].
BTW, this is not valid JSON.
From Windows, for sure ...
On 29 Jan 2018, at 18:49, Clément Bera <bera.clement@gmail.com> wrote:
Hi,
I am currently parsing lua and JSON-like file in Pharo. They contain both Simplified and Traditional Chinese characters for comments and for strings displayed in the UI. Lua files are parsed correctly. However the JSON-like files aren't.
In attachment I put one of the problematic file with Simplified chinese characters (I've also copied the file at the end of the mail). The problem can be shown as follow in Pharo:
'schinese.txt' asFileReference readStream contents
The contents function sends a UTF8InvalidText 'Invalid utf8 input detected' error. However my text editor correctly displays the file and it is correctly parsed by the Lua runtime (The program parsed has been deployed in production for years and works fine).
What can I do to parse this file correctly from Pharo ?
Thanks,
Below is the file content, non Chinese people may not have the font to display the characters, note that I have no idea what is written in Chinese (Please don't hold me responsible if there are offending contents):
"lang" { "Language" "Schinese" "Tokens" { "text_store_cd" "è´å£³ååºçåå伿¯å¤©éæºå·æ°! 䏿¬¡å·æ°å·å´æ¶é´" "text_cannot_huidaoguoqu" "ç°å¨ä¸è½ä½¿ç¨åå°è¿å»~" "tips1" "å©ç¨é¼ æ æ»è½®å¯ä»¥è°èè§è§è·ç¦»ï¼æ¹ä¾¿ä½ æ¥çåºå°å ¨è²~" "tips2" "éè¿å ¨é¨50å ³ä»¥åä½ è¿å¯ä»¥ç»§ç»æææ´å æé¾åº¦çæ å°½è¯ç¼æ¨¡å¼ï¼" "tips3" "æ¯å¤©æ©æ¨è´å£³ååºä¼éæºå·æ°åéæºææï¼çå¿ä½ æ³è¦çååï¼" "tips4" "æè¡æ¦çå25åå¯ä»¥è·å¾çå å¥ç« ï¼è±¡å¾çä½ å¨å¡é²æ¸¸æä¸çåè¶æç»©ï¼" "tips5" "æ¯10æ³¢æäººä¼æä¸ä¸ªBOSSå ³å¡ï¼å®æ¯æ®éæäººæ´é¾å»æ~" "tips6" "é£è¡çæäººä¸ä¼è¢«ç³å¤´é»æ¡ï¼æä»¥ä¸è½å©ç¨è¿·å®«æ¥å¢é¿æªç©ç线路~" "tips7" "å¼å±çæ¶åç¹å»å·¦ä¸æ¹çè±é鿩徿 å¯ä»¥æ¥çå¹¶éæ©ä½ æ¥æçè±éï¼" "tips8" "é身çæäººå¿ é¡»éè¿èç½ç³»åå¡çç §æå ç¯æè½è¢«åç°ï¼" "tips9" "ç¹å»å³ä¾§çåæå ¬å¼æé®å¯ä»¥æå¼åæé¢æ¿ï¼äºè§£é«çº§å¡çåæä»¥åå½åé ä»¶ç¶æ~" "tips10" "é请好åä¸èµ·æ¸¸æï¼å¯ä»¥äºç¸åä½å ±å对æå¼ºå¤§çæäººï¼" "tips11" "ç³æ¿ä¼å¯¹è¸©ä¸å»çæäººäº§çææï¼æä»¥æå¥½æ¾ç½®å¨æäººå¿ ç»ç路线ä¸~" "tips12" "为è±éè´ä¹°ç¾ä¸½çç¹æï¼å½ä½ å¯ä»¥ä¸åååæçæ¶åææé ä»¶é½ä¼æç¹ææç¤ºï¼" "tips13" "æ¯åå伤害æé«çå¡å°ä¼è·å¾æå¤10å±çMVPå ç¯ï¼å¢å ç©çåéæ³è¾åºï¼" "tips14" "æ¯ä¸ªæçæåä¸å¤©æ¯èµå£ç»ç®æ¥ï¼å°ä¼æ ¹æ®ä½ è¿èµå£çæåé¢å丰åçè´å£³å¥å±ï¼" "tips15" "妿ä¸ç¥éææ ·é 迷宫ï¼ä½ å¯ä»¥ç¹å»å³ä¾§ç迷宫æåæé®æ¥çæè å享æ¨èç迷宫~" } }
-- Clément Béra Pharo consortium engineer https://clementbera.wordpress.com/ Bâtiment B 40, avenue Halley 59650 Villeneuve d'Ascq <schinese.txt>