简体   繁体   English

json文件中的特殊字符

[英]Special Characters in json file

So i'm trying out googles add to home screen function and I'm trying to get the title of my web app to display a special character in it but don't know how. 因此,我正在尝试将Google添加到主屏幕功能,并且正在尝试获取网络应用程序的标题以在其中显示特殊字符,但不知道如何操作。

{
  "name": "aésmé",
  "icons": [
    {
      "src": "img/icon.png",
      "sizes": "192x192",
      "type": "image/png",
      "density": "4.0"
    }
  ],
  "start_url": "index.php",
  "display": "standalone",
  "orientation": "portrait"
}

I suspect that this is a charset issue. 我怀疑这是一个字符集问题。 Make sure that the encoding with which the file is saved matches the encoding reported by the server when the file is served up. 确保保存文件时使用的编码与服务器报告的编码匹配。 If you're using Apache and you've saved the file in UTF-8 (highly recommended), then add the following to your .htaccess file (or to the server config file, if that's accessible to you): 如果您使用的是Apache,并且已将文件保存为UTF-8(强烈建议),则将以下内容添加到您的.htaccess文件(或服务器配置文件(如果您可以访问)中):

AddType 'application/json; charset=UTF-8' .json

It wouldn't hurt to also add: 也可以添加以下内容:

AddDefaultCharset utf-8

Note that in theory (according to the application/json spec ), you must use some sort of Unicode encoding for your file (UTF-8, UTF-16 (BE or LE), or UTF-32 (BE or LE)). 请注意,理论上(根据application/json规范 ),您必须对文件使用某种Unicode编码(UTF-8,UTF-16(BE或LE)或UTF-32(BE或LE))。 Make sure you have saved the file in one of those encodings. 确保已使用其中一种编码格式保存了文件。 Also, the default character set (what the browser uses when no charset is specified) is UTF-8. 另外,默认字符集(未指定字符集时浏览器使用的字符集)为UTF-8。 However, browsers vary quite a bit from this. 但是,浏览器与此相差很大。

It can be one of two: 1. You are messing up with the utf8 conversion. 它可以是以下两种之一:1.您搞砸了utf8转换。 You either didn't convert, or worse, did it twice tesulting with strange looking characters. 您要么没有转换,要么更糟的是,两次都用看起来奇怪的字符进行了测试。 2. If you need to use special characters consider using base64, although it would render the text unreadable in a text editor. 2.如果您需要使用特殊字符,请考虑使用base64,尽管它会使文本在文本编辑器中不可读。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM