Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua - Printing ( ♡ ) character after parsing of JSON

Tags:

json

utf-8

lua

Here is my function, I am using lua-cjson which says it fully supports UTF-8

function getPersonaName(sid64)
local cjson = require "cjson"
local r = http.request("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=###&steamids=" .. sid64)
results = cjson.decode(r)
personaname = results.response.players[1].personaname
return personaname

When the user has some special character like ♡ my Lua code returns the personaname as

tam ♡

instead of

tam ♡

How can I correctly return the exact result?

like image 859
Fiat Pax Avatar asked Aug 16 '13 15:08

Fiat Pax


1 Answers

That's an encoding issue. Whatever you are outputting the results to isn't expecting the UTF-8 encoded character you are sending it and so it is displaying it as best it can.

If you are in control of the display side of things then you need to look into changing the encoding it expects (or looking into how you can convert the UTF-8 into whatever encoding it does expect).

If you aren't in control of the display then there isn't much you can do about this other than to inform your users that they need to have their side of things configured correctly.

like image 200
Etan Reisner Avatar answered Oct 03 '22 09:10

Etan Reisner