UTF-8在Lua/Corona中显示不正确 [英] UTF-8 incorrectly displayed in Lua/ Corona

查看:87
本文介绍了UTF-8在Lua/Corona中显示不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Lua中,对于一个iPad Corona项目,我正在使用network.request请求一个UTF-8服务器文本文件(包含汉字),但是在控制台或应用程序中显示时,结果显示为垃圾" .例如,谷歌浏览器会显示相同的UTF-8页面,因为当服务器(使用PHP)将其发送到"Content-Type:text/plain; charset = utf-8'(并且没有BOM,也没有字节顺序标记).我在Lua中看到的垃圾"外观类似于我使用选项菜单强制" Chrome将页面呈现为ISO-8859-1的情况.

In Lua, for an iPad Corona project, I'm requesting a UTF-8 server text file (containing Chinese characters) using network.request, but the result when displayed in the console or in the app shows as "garbage". Google Chrome, for instance, displays the same UTF-8 page fine, as I'm setting the http header when the server sends this (using PHP) to 'Content-Type: text/plain; charset=utf-8' (and there's no BOM, byte order mark either). The "garbage" I'm seeing in Lua looks similar to when I "force" Chrome to render the page as ISO-8859-1 using the options menu.

有人有任何帮助或指示吗? 如果所有其他方法都失败了,我将如何在Lua中将垃圾"字符串转换回其UTF-8起源?

Does anyone have any help or pointers? If all else fails, how would I convert the "garbage" string back to its UTF-8 origins within Lua?

感谢您的帮助!

推荐答案

Lua对UTF-8一无所知. Lua字符串只是字节序列.听起来Corona本身正在将字符串解析为ISO8859-1.造成这种情况的最可能原因是他们所做的事情确实愚蠢而幼稚,例如将字符串的每个字节都视为Unicode代码点.

Lua doesn't know anything about UTF-8; Lua strings are just sequences of bytes. It sounds like Corona itself is parsing the strings as ISO8859-1. The most likely cause for this is them doing something really stupid and naive like treating each byte of the string as a Unicode code point.

恐怕我不了解Corona,因此无法提供任何特定的解决方案,但是我建议您查看一下包含编码的函数---可能存在特定的函数来呈现例如,具有特定编码的字符串.

I'm afraid I don't know Corona, so can't provide any specific solutions, but I'd suggest looking to see what functions it's got that involve encodings --- there may be a specific function to render a string with a particular encoding, for example.

这篇关于UTF-8在Lua/Corona中显示不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆