I have a set of codes where i have done error handling. I want the result to be {"ErrorMessage": Server is down} However i keep getting the result as {"ErrorMessage":"Server is down"}.
Here are my codes:
catch (Exception e) { var result = "Server is down"; return Ok(new { ErrorMessage = result }); } I have tried using '@' and '\' characters however it did not work. How do i escape those extra double quotes? Someone please do help me. Thank you so much in advance.
{"ErrorMessage": Server is down}is invalid JSON. See json.org for confirmation: A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. Are you absolutely, positively sure you want that?{"ErrorMessage":"Server is down"}is already the right way. That's a valid JSON object with a single property namedErrorMessagewhose value is the stringServer is down. Or by Please let me know the right way to do this do you mean, "Please tell me how to generate this invalid JSON anyway, I am absolutely positively sure I need it."{"ErrorMessage":"Server is down"}is correct so thanks :)true,falseornull.