Need a single backslash in JSON response using ASP.NET Web API. The following is the object that been converted to JSON:
public RunTypeCanNotContainSpecialCharacters()
{
SourceErrorCode = ApiExceptionCode.RunTypesErrorCodes.RunTypeCanNotContainSpecialCharacters;
StatusCode = HttpStatusCode.BadRequest;
ErrorCode = ApiExceptionCode.RunTypesErrorCodes.RunTypeCanNotContainSpecialCharacters;
Scenario = "{The following special characters are not supported.[ '/', '#', '?', ',', '\\']}";
}
On object creation if I keep single slash then it gets omitted in the response, but on using more than one slash, it keeps that number of slashes in the response object.
During debugging, I found out that during the last line of constructor i.e is for Scenario
property assignment everything is happening.
I have tried using raw string i.e using @
but this add extra backslash in case of ASP.NET, but in console apps it shows single backslash.
In response I want the following output specifically for userMessage
:
"errors":
[
{
"userMessage": "{Key:The following special characters are not supported.[ '/', '#', '?', ',', '']}",
"errorCode": "RunTypesErrorCodes.RunTypeCanNotContainSpecialCharacters",
"devMessage": "No error arguments available.",
"moreInfo": null
}
]
I tried many ways like JsonConvert.SerializeObject
, Json.Encode
and Regex.Unescape
– but none are working.
These characters are not allowed in PartitionKey
and RowKey
nitish jarmal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1