riseres riseres - 3 months ago 19
JSON Question

Return Json, but it includes backward slashes "\", which i don't want

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

the problem is it comes with "backward slashes".

I also added this code to Global.asax.

GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();


here is what it returns.

"{\"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}"


so what i want to see is

{"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}


here is JsonConvetor

string json = JsonConvert.SerializeObject(myObj);

Answer

i found the solution here it is

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