Reputation: 307
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.
Upvotes: 1
Views: 195
Reputation: 307
I have decided to leave the result as it is as {"ErrorMessage":"Server is down"}
is the correct way of displaying a JSON output. As explained by @dbc, that is a valid JSON object with a property named ErrorMessage
whose value is the string Server is down
.
Upvotes: 1