我正在为JSON服务使用WCF,格式如下:
[OperationContract]
[ServiceKnownType(typeof(ComplexResult))]
[WebInvoke(
Method = "GET",
BodyStyle = WebMessageBodyStyle.Bare,
ResponseFormat = WebMessageFormat.Json)]
MyClass MyFunction(string myParams);这很有效,但它也有局限性。我不能忽略我要序列化为JSON的类的属性。如果我使用JavaScriptSerializer类,那么我可以将ScriptIgnore属性放在我想忽略的属性上,并且它们不会在JSON中被序列化,但是这不适用于上面的方法。
有没有办法排除使用JSON Json方法序列化到ResponseFormat的类的属性?
发布于 2011-10-19 11:10:00
默认情况下,WCF使用DataContractJsonSerializer序列化对象。根据MyClass的定义方式,您可以使用不同的属性来防止成员被序列化:
[IgnoreDataMember]属性[Serializable]修饰,则可以在这些成员中使用[NotSerialized]属性https://stackoverflow.com/questions/7815885
复制相似问题