svc 网络服务响应包含额外的双引号

svc webservice response contains extra double qotation

我有一个 json 存储在数据库中的 ntext 字段中,我想 return 在 svc (c#) webservice 中,webservice 是 get 并且响应类型是字符串,如下所示:

    [WebInvoke(Method = "GET",
       ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "gcwbcc/{cityCode}/{key}")]

但结果我得到了额外的双引号,json 中的所有双引号都转换为 \" 然后我有两个问题,一个是额外的双引号,第二个是将结果转换为 " 到 \"。

我通过将 return 类型的网络方法更改为流来解决它 并编写了这行简单的代码:

byte[] resultBytes = 编码。UTF8.GetBytes(结果); WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8"; return 新内存流(结果字节);

参考: Returning raw json (string) in wcf 但这是原始指南 https://blogs.msdn.microsoft.com/carlosfigueira/2008/04/17/wcf-raw-programming-model-web/