WCF + Json = wrong serialization

后端 未结 3 1118

Why this WCF 3.5 method

[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Jso         


        
相关标签:
3条回答
  • 2021-01-06 20:39

    This is a security feature that has been added to the JSON serialization in .NET 3.5. It's a container object, so instead of, say, results[0], you would just say results.d[0]. Read this article for more information.

    0 讨论(0)
  • 2021-01-06 20:40

    Have you tried changing the BodyStyle property of your [WebGet] Attribute so that responses aren't wrapped?

    0 讨论(0)
  • 2021-01-06 21:02

    I'm assuming you are using <enableWebScript/> in your behavior config, replace that with <webHttp defaultOutgoingResponseFormat="Json"/> and you will get json without the root "d" and without the "__type" props.

    However, I've only tested this in 4.0

    I also don't use any attributes in code.

    0 讨论(0)
提交回复
热议问题