【问题标题】:Play Framework *.json template is not utf-8. why? and how can I set it to utf-8?Play Framework *.json 模板不是 utf-8。为什么?以及如何将其设置为 utf-8?
【发布时间】:2012-01-27 17:00:04
【问题描述】:

我正在使用 play 框架,当前版本为 1.2.4。

我想拥有自己的 json 结构,不想返回完整的对象。所以我决定使用json模板。

简单的例子。

控制器:

Service service = Service.find("byIdAndCompany", new Long(serviceId), company).first();
    if (service != null) {
        render(service);
    }

所以我得到一个完整的服务对象并返回它。

我的 json-template 非常容易用于测试目的:

{
    "serviceName": "${service.name}"
}

就是这样。但是 Content-Type 只是“application/json”,如果我将使用给定的 renderJSON() 方法返回整个服务对象,那么它是正确的 UTF-8 并且 Content-Type 是“application/json; charset=utf- 8"。

对于带有元音变音的德国人,元音变音和其他特殊字符无法正确显示。

【问题讨论】:

    标签: json templates utf-8 playframework


    【解决方案1】:

    确保您的 JSON 模板文件编码设置为 UTF-8。 (详情请参阅Play Framework documentation。)

    【讨论】:

      猜你喜欢
      • 2019-04-12
      • 2016-05-11
      • 2013-06-20
      • 2018-03-04
      • 1970-01-01
      • 2014-11-02
      • 2013-03-04
      • 2015-04-13
      • 1970-01-01
      相关资源
      最近更新 更多