Search code examples
c#jsonwcfrestresponse

C# JSON Rest Response String


C# noob here.

I'm doing a simple wcf service RestAPI, so far so good...but my json string response isn't coming out the way i wanted.

Actual response: {"GetInfoResult":{"Name": "John"}}

Desired response: {"Name": "John"}

how do I remove GetInfoResult field?

Thanks


Solution

  • You should be able to just set the BodyStyle to WebMessageBodyStyle.Bare on your WebGet annotation, the default is WebMessageBodyStyle.Wrapped that adds the wrapper you don't want;

    [WebGet(BodyStyle = WebMessageBodyStyle.Bare)]