【发布时间】:2011-10-19 11:10:00
【问题描述】:
我将 WCF 用于使用这种格式的 JSON 服务:
[OperationContract]
[ServiceKnownType(typeof(ComplexResult))]
[WebInvoke(
Method = "GET",
BodyStyle = WebMessageBodyStyle.Bare,
ResponseFormat = WebMessageFormat.Json)]
MyClass MyFunction(string myParams);
这很好用,但是它有一个限制。我不能忽略要序列化为 JSON 的类的属性。如果我使用 JavaScriptSerializer 类,那么我可以将 [ScriptIgnore] 属性放在我想忽略的属性上,它们不会在 JSON 中序列化,但这不适用于上述方法。
有没有办法排除使用 ResponseFormat Json 方法序列化为 JSON 的类的属性?
【问题讨论】: