doutao5419 2012-10-25 19:08
浏览 252

iOS App表情符号问题 - JSON没有正确编码它们

Sorry this may sound like madness. So the main issue is that if my data from the web service is json_encoded then most emojis show up as squares in the app. Not all but most. I am trying to fix this on the web service side.

I found that if I do not use json_encode, the instead do something like:

$array .= '{"text":"emoji"}
echo = '[' . $array . ']';

Basically echoing it as if its json encoded. The emojis show up correctly in the app, but other things doing work properly because its not encoded. So what I figured out using mb_detect_encoding is that the text that has an emoji is UTF-8 and ones that don't have emoji are ASCII. So what I did is check that I can check and see if its not UTF-8 and if its not just json_encode the string. And if it is UTF-8 and do nothing to it. That works for 95% of all the data that is returned. Something like below.

$encode = mb_detect_encoding($theMemo);
if($encode != 'UTF-8'){
$theMemo = json_encode($theMemo);
}

$array .= '{"text":"' . $theMemo . '"}
echo = '[' . $array . ']';

The issue I am having is there are time such as when the text is something like "Floyd Mayweatherâ€@FloydMayweather #TheMoneyTeam" which has some unicode in it, but its not the emojis so I need to json_encode it for it to show up right.

Basicly I need to find a way to either json_encode anything that does not have a emoji in it or find a more proper way of going about this. I know what I am doing may seem odd, but I am just trying to find a solution, even if it seems like a hack.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 制裁名单20240508芯片厂商
    • ¥20 易康econgnition精度验证
    • ¥15 线程问题判断多次进入
    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接