本文介绍了更改默认JSON序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP.NET默认JSON序列化是缓慢的,而我需要很多的性能,所以我想用,是有办法,我可以使用,而不是一个默认?

ASP.NET default json serializer is slow, and I need a lot of performance, so I want to use ServiceStack.Text Serializer, is there a way I can use that serializer instead of the one by default?

如果我发送一个JSON请求我的ASMX文件,并返回一个对象,将使用微软的执行慢序列化。

If I send a JSON request to my ASMX file, and return an object it will serialize it using Microsoft's slow implementation.

我想我随时可以返回一个字符串,并手动序列化,但我只是想知道,如果这是可能的。

I guess I could always return a string, and serialize manually, but I just want to know if it's possible.

推荐答案

签出此链接:

基本上,你需要把你的自定义转换器配置标记在web.config中:

Basically you need to put your custom converter in configuration tag on web.config:

<configuration>
  <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="50">
          <converters>
            <add name="MyCustomConverter"
              type="MyCompany.ConvertersNameSpace.MyTypeConverter"/>
          </converters>
        </jsonSerialization>
      </webServices>
    </scripting>
  </system.web.extensions>
</configuration>

由于需要的JavaScriptSerializer告知哪些类的支持,我想asp.net就会认为你不是序列化器的默认串行的。

Since JavascriptSerializer needs to inform which classes are supported, i think asp.net will assume your serializer instead of default serializer.

这篇关于更改默认JSON序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 09:44
查看更多