I have the following controller:
public IActionResult Get()
{
var res = GetResult();
// res is a JSON {"hello": "howareyou"}
return Ok(res);
}
I’m getting in the result:
{"hello": "how\are\you"}
How to remove the double slash from the reusult? Why they’re being added?
3
Answers
Because that’s how you print a backslash in JSON.
is a special character. It pairs with the next character(s) to define what it prints. For example,
n
means to add a new line, not printing "n".\
means a print a single backslash.The server (your code) and the client using your application will understand this escape sequence just fine.
You don’t need to remove them since you have them in json already. If you want to get rid of them fix json of the action
These are not part of the string but only one i.e. is part of string. another is added as a escape character only.
if you print this you will only get single slash not double these are just representational value at the time of debug only.
Check live code : here
Escape Characters