Need an Single backward slash in Json response using ASP.Net web api.Following is the object that been converted to json objec
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 response but on using more than one slash then it keeps those same number of slashes in 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 back slash.
.
In response i want following output spefically 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
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.