我使用MVC4 Web API,C#,并想 **使用Json.net 返回Json 。**
问题是它带有“反斜杠”。
我还将此代码添加到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}
这是JsonConvertor
string json = JsonConvert.SerializeObject(myObj);
我在这里找到解决方案
return new HttpResponseMessage() { Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json") };