Web Connection User Discussions
Fail to return utf-8 coding in REST API Services
Gravatar is a globally recognized avatar based on your email address. Fail to return utf-8 coding in REST API Services
  Eddie Tan
  All
  May 18, 2022 @ 09:24pm

My actual Json data: Raw Data : {"title": "English:'Hello' UTF-8:'??'"}

Return from Web Connection. V7.26

Follow the Documentation, had enabled response to encoding it utf-8.

FUNCTION OnProcessInit
Response.Encoding = "UTF8"
Request.lUtf8Encoding = .T.

Web Connection server side code :

FUNCTION testUTF8
Sys(3101,65001)    &&UTF8
p_filename = "sample.json"
lcUTF8= filetostr(p_filename )
loSer = CREATEOBJECT("wwJsonSerializer")
loResult = loSer.DeserializeJson(lcUTF8)
RELEASE loSer 
RETURN loResult 

Could anyone figure out, which parts I did mistake?

Refer Doc : https://www.west-wind.com/presentations/foxunicode/foxunicode.html

Gravatar is a globally recognized avatar based on your email address. re: Fail to utf-8 coding in RESP API Services
  Rick Strahl
  Eddie Tan
  May 18, 2022 @ 10:24pm

What is the actual problem and the final output?

I think the problem isn't the Web Connection application - it's doing the right thing and returning UTF-8 it looks like (return some HTML and display in the browser with that same string) - I'm not sure what the characters should look like UTF-8 encoded.

Before you pass to the JSON deserialization you need to decode the UTF-8 encoding using STRCONV(lcJson, 11). I assume you are using a Chinese code page? Otherwise you can't decode Chinese characters into FoxPro and only get ??.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Fail to utf-8 coding in RESP API Services
  Eddie Tan
  Rick Strahl
  May 18, 2022 @ 11:15pm

Yes, is Chinese Code Page 936, in Foxpro. After UTF-8 encoding using STRCONV(lcJson, 11), Result :

As I understand, should not using STRCONV(lcJson, 11) , because should pass UTF-8 coding into loSer.DeserializeJson().

I used STRCONV(lcJson, 11,2052) can successfully convert UTF-8 to DBCS, and appear DBCS correctly by using Foxpro TextBox. I had try google many ways, still can't deserialize correctly, doesn't know which parts go wrong.

My POS program retrieve and save UTF-8 data into Firebase Database thru ODBC correctly. I used https://www.hexagora.com/en_home.asp TextBox to edit UTF-8 Coding data field correctly.

https://en.wikipedia.org/wiki/Code_page_936_(Microsoft_Windows)

Gravatar is a globally recognized avatar based on your email address. re: Fail to utf-8 coding in RESP API Services
  Rick Strahl
  Eddie Tan
  May 19, 2022 @ 09:05am

I'm not sure what you mean.

The server is doing the right thing - it's returning the UTF-8 string.

You need to apply the STRCONV() on the client after you've retrieved the UTF-8 encoded content from the Web Server.

+++ Rick ---

© 1996-2022