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!

2
  • 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. Commented Feb 27, 2014 at 18:57
  • 1
    Found an answer for your question here: stackoverflow.com/questions/17097841/… Commented Mar 12, 2014 at 10:03

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
Hi, what is your client aspx html/js , will try n drop u the code ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.