translate a unicode string

I have a foreign language in chinese,

I have no problem on other unicode strings like “é”

but whenever I use another language that returns a unicode “光” it returns as is, it doesn’t return a text that I desire which is “光”,

If I manually input “光” in my code, it will automatically displayed, but all of my chinese char’s are sent to me by a unicode, I hope you understand my question :slight_smile:

How are you getting your data into your app?

via web server using JSON,

Let me re-ask the question, are you using network.request() or network.download() to get the file?  Can you post your code you’re using to fetch the file?

network.request

local function networkListener( event ) if ( event.isError ) then print( "Network error!") else if event.phase == "began" then print("hello") elseif event.phase == "ended" then print("hi") myNewData = event.response -- print ("From server : "..myNewData) decodedData = (json.decode( myNewData)) SaveData() else end end end network.request( "The webserver site(JSON display only)", "GET", networkListener )

Have you tried setting a header in your network.request?

http://docs.coronalabs.com/api/library/network/request.html

local params = {} params.headers = {["Content-Type"] = "text/html; charset=utf-8"} network.request( "The webserver site(JSON display only)", "GET", networkListener, params )

@ingemar it still doesn’t work and im using a php as a backend

In which character set is your Chinese text encoded?

It looks like you have a character set mismatch between the file on your server and Corona. Corona wants to have characters in UTF-8 format. 

If you make sure your Chinese text is in UTF-8 format you should be OK.

I don’t know but it’s like this &#20809 ;

That looks like a URL-escaped string. It will work in a web-view, but not in a Corona text string. You’ll need to get that into UTF-8.

I was hoping that url.unescape() would work, but it didn’t, so unfortunately I’m not aware of anything that converts such escaped strings to UTF-8-characters in Corona.

Where does the Chinese text come from?

It would be best if the text in the file on the server was UTF-8 to begin with.

Another option would to do a urldecode() on the string in your PHP script.

It is already in UTF-8 though, but still thanks for the info, it comes from the server it will be manually inputed, by now I copy paste it

I still think that a urldecode() in your PHP script thats builds your JSON response would do the job…

How are you getting your data into your app?

via web server using JSON,

Let me re-ask the question, are you using network.request() or network.download() to get the file?  Can you post your code you’re using to fetch the file?

network.request

local function networkListener( event ) if ( event.isError ) then print( "Network error!") else if event.phase == "began" then print("hello") elseif event.phase == "ended" then print("hi") myNewData = event.response -- print ("From server : "..myNewData) decodedData = (json.decode( myNewData)) SaveData() else end end end network.request( "The webserver site(JSON display only)", "GET", networkListener )

Have you tried setting a header in your network.request?

http://docs.coronalabs.com/api/library/network/request.html

local params = {} params.headers = {["Content-Type"] = "text/html; charset=utf-8"} network.request( "The webserver site(JSON display only)", "GET", networkListener, params )

@ingemar it still doesn’t work and im using a php as a backend

In which character set is your Chinese text encoded?

It looks like you have a character set mismatch between the file on your server and Corona. Corona wants to have characters in UTF-8 format. 

If you make sure your Chinese text is in UTF-8 format you should be OK.