1

当我通过 JsonDataContractCodec OpenRasta 将我的对象作为 JSON 返回时,将 Content-Type 标头设置为

应用程序/json

但忽略内容类型的字符集部分。

当我使用 Chrome 时,它​​会发送带有以下标头的 GET 请求:

接受字符集:windows-1251,utf-8;q=0.7,*;q=0.3

我所有的 utf-8 编码的 json 对象都出错了。

我试图在没有运气的情况下覆盖 OperationResult。OpenRasta 用编解码器的标题覆盖我的标题。

4

1 回答 1

0

刚刚找到了一种方法 - 从 JsonCoder 继承并应用MediaTypeAttribute

[MediaType("application/json; charset=utf8")]
public class JsonWithEncoding:JsonDataContractCodec
{

}

并注册处理程序:

ResourceSpace.Has
  .ResourcesOfType<IEnumerable<ProfileResource>>()
  .AtUri("/profiles")
  .HandledBy<ProfileHandler>()
  .TranscodedBy<JsonWithEncoding>();

但是这种方式是非常静态的:(

于 2011-02-17T06:39:33.947 回答