如何从JSONifying JSON停止ASP .NET

时间:2017-07-05 18:43:56

标签: asp.net asp.net-web-api

我目前正在尝试打包内部API并将其设为外部API。为此,我尝试从内部API中继JSON响应,并在有人发出get请求时发送该确切响应。相反,ASP .NET是JSONifying那个子并添加额外的反斜杠作为转义字符(实际上这些斜杠实际上是内部api放入的斜杠)。

我怎样才能得到它,所以asp不会将字符串jsonify

1 个答案:

答案 0 :(得分:1)

您可以直接将json数据写入响应并设置正确的内容标题。

public HttpResponseMessage GetData()
{
    var json = "\"value\": \"da\\ta\"";
    var resp = Request.CreateResponse(HttpStatusCode.OK);
    resp.Content = new StringContent(json);
    resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
    resp.Content.Headers.ContentEncoding = //your json encoding, you can get it from response inner API

    return resp;
}