我使用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,“WT50JB”,“WT50JB”,“detail”:“sdf?”,"unit":2,"time_in":"2012-12-11T19:00:00",time_in "time_used_dd":0.0,"time_used_hh":0.0}
这是JsonConvertor
string json = JsonConvert.SerializeObject(myObj);
发布于 2017-02-21 10:30:51
我找到了解决方案,而且它对我有用:
var json = JsonConvert.SerializeObject(sb.ToString(), Formatting.Indented);
response.Content = new StringContent(json, Encoding.UTF8 , "application/json");
https://stackoverflow.com/questions/13833900
复制相似问题