返回 Json,但它包含反斜杠“",这是我不想要的 [英] Return Json, but it includes backward slashes "", which I don't want

查看:26
本文介绍了返回 Json,但它包含反斜杠“",这是我不想要的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 MVC4 web-api、c#,并且想返回 Json 使用 Json.net.

I use MVC4 web-api, c#, and want to return Json using Json.net.

问题在于它带有向后斜线".

The problem is it comes with "backward slashes".

我也将此代码添加到 Global.asax.GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();

I also added this code to Global.asax. GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();

这是它返回的内容:

"{"cid":1,"model":"WT50JB","detail":"sdf??","unit":2,"time_in":"2012-12-11T19:00:00","time_out":"2012-12-12T13:00:06.2774691+07:00","time_used_dd":0.0,"time_used_hh":0.0}"

所以我想看到的是:{"cid":1,"model":"WT50JB","detail":"sdf??","unit":2,"time_in":"2012-12-11T19:00:00","time_out":"2012-12-12T13:08:50.5444555+07:00","time_used_dd":0.0,"time_used_hh":0.0}

So what I want to see is this: {"cid":1,"model":"WT50JB","detail":"sdf??","unit":2,"time_in":"2012-12-11T19:00:00","time_out":"2012-12-12T13:08:50.5444555+07:00","time_used_dd":0.0,"time_used_hh":0.0}

这里是 JsonConvertor

Here is JsonConvertor

string json = JsonConvert.SerializeObject(myObj);

推荐答案

我在这里找到了解决方案

i found the solution here it is

return new HttpResponseMessage() 
{
    Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json")
};

这篇关于返回 Json,但它包含反斜杠“",这是我不想要的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆