如何不序列化 JSON 对象上的 __type 属性 [英] How to not serialize the __type property on JSON objects
问题描述
我从 ScriptService
的 WebMethod
返回的每个对象都被包装到一个 JSON 对象中,数据位于名为 d
的属性中.没关系.但我不希望将额外的 __type
属性提供给客户端,因为我使用 jQuery 进行手动处理.
Every object I return from a WebMethod
of a ScriptService
is wrapped into a JSON object with the data in a property named d
. That's ok. But I don't want the additional __type
property to be served to the client, since I do manual processing with jQuery.
有可能吗?
推荐答案
我发现,如果我让我的类的默认构造函数使我的 webmethod 返回除 public 以外的任何内容,它不会序列化 __type:ClassName代码>部分.
I found that if I make the default constructor of my class that my webmethod returns anything other than public it will not serialize the __type:ClassName
portion.
你可能想声明你的默认构造函数 protected internal ClassName() { }
You may want to declare your default constructor protected internal ClassName() { }
这篇关于如何不序列化 JSON 对象上的 __type 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!