3

I have the following c# string that is JSON formatted.

string myString = "{color: \"red\", value: \"2\"}";

When I send this string as a response from my Controller it returns to the client with the escape characters intact.

Here is the code for my Controller I am using to return the string:

public class MyController : BaseController
{

    [HttpPost]
    public virtual HttpResponseMessage Post()
    {
         string myString = "{color: \"red\", value: \"2\"}";
         HttpResponseMessage response = this.Request.CreateResponse(HttpStatusCode.OK, myString, "application/json");
         return response;
    }
}

My questions is: How do I return the string 'myString' to the client without the escape characters showing up on the client end?

Thank you!

james
  • 712
  • 4
  • 11
  • 29
  • They shouldn't show up on the client end because those escape characters aren't encoded into the string. They should simply be evaluated by the compiler. – McAden Feb 27 '14 at 18:57
  • 1
    Found an answer for your question here: http://stackoverflow.com/questions/17097841/return-a-json-string-explicitly-from-asp-net-webapi – oldbam Mar 12 '14 at 10:03

1 Answers1

0

Assume your using Web-API, it returns data by default in Json format which is escaped, you can get Web-API to return XML, but either way it will be formatted one way or the other, looks like you need to de-serialise the Json and then it will remove the escaped chars.

fuzzybear
  • 2,325
  • 3
  • 23
  • 45
  • I know there is a way to deliver the content to the client and not see the escape characters. I have seen it. My opinion is that the client does not need to deserialize the json. – james Feb 27 '14 at 21:19
  • Hi, what is your client aspx html/js , will try n drop u the code ? – fuzzybear Mar 01 '14 at 00:27