Extra slashes("\) in Redis cache

  • Thread starter Thread starter pmjn
  • Start date Start date
P

pmjn

Guest
Hi All,

I have a C# application in which I am serializing an object to JSON string and this output JSON is sent to Redis cache and stored there. Below is the code to achieve the same:

var setting = new JsonSerializerSettings();

setting.StringEscapeHandling = StringEscapeHandling.EscapeNonAscii;

MyMessage<T> t = new MyMessage<T>(objMessage);

string json = JsonConvert.SerializeObject(t, Formatting.None, setting);

invocationTask = hubProxy.Invoke("CreateMessage", MessagePath, json);



JSON string returned from JSONConvert.SerializeObject() method contains escape slashes("\") in it. This JSON is sent to Redis via Proxy method CreateMessage() and stored there. Below is the format of this JSON data in Redis cache-

{"MessageDateTime":"2020-03-30T20:37:13.8183044+05:30","Message":"{\"PersonId\":\"144235\",\"FirstName\":\Mark"\",\"LastName\":Wright,\"Address\":null,\"IsModified\":\"False\"}"}


I don't want to include these extra slashes("\") in this data. Please let me know the best way to achieve this ASAP.

Regards,

PMJN

Continue reading...
 
Back
Top