【发布时间】:2015-06-14 08:28:24
【问题描述】:
目前在我的 web API 中实现了下面提到的类
public class ServiceStackTextFormatter : MediaTypeFormatter
{
public ServiceStackTextFormatter()
{
JsConfig.DateHandler = JsonDateHandler.ISO8601;
SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
SupportedEncodings.Add(new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true));
SupportedEncodings.Add(new UnicodeEncoding(bigEndian: false, byteOrderMark: true, throwOnInvalidBytes: true));
}
}
我只想知道如何在 ServiceStack 中实现 JSNOP,我知道我们可以使用 Newtnsoft json 来实现它。我试过使用下面提到的代码,它工作正常。
public class FormatterConfig
{
public static void RegisterFormatters
(MediaTypeFormatterCollection formatters)
{
var jsonFormatter = formatters.JsonFormatter;
jsonFormatter.SerializerSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
formatters.Insert(0, jsonFormatter);
var jsonpFormatter =
new JsonpMediaTypeFormatter(formatters.JsonFormatter);
formatters.Insert(1, jsonpFormatter);
}
}
所以我只想知道如何使用 ServiceStack?
【问题讨论】:
标签: c# jsonp servicestack