Reputation: 385
I have a Json
saved in database as string:
"{ \"path\" : \"a.crx\", \"uniteDeVolume\" : \"g or ml\", \"unites\" : \"Acts/Volume\", \"nbIndevMin\" : \"20\", \"nbJours\" : \"6 to 7\", \"ventilDepart\" : \"20051\" }"
When I want to read this field from database, and to deserialize to BsonDocument, the returned value is
"\"{ \\\"path\\\" : \\\"a.crx\\\", \\\"uniteDeVolume\\\" : \\\"g or ml\\\", \\\"unites\\\" : \\\"Acts/Volume\\\", \\\"nbIndevMin\\\" : \\\"20\\\", \\\"nbJours\\\" : \\\"6 to 7\\\", \\\"ventilDepart\\\" : \\\"20051\\\" }\""
How to eleminate the escape characters?
Upvotes: 1
Views: 324
Reputation: 46
I would use Regex from 'System.Text.RegularExpressions'
var escapedString ="\"{ \\\"path\\\" : \\\"a.crx\\\", \\\"uniteDeVolume\\\" : \\\"g or ml\\\", \\\"unites\\\" : \\\"Acts/Volume\\\", \\\"nbIndevMin\\\" : \\\"20\\\", \\\"nbJours\\\" : \\\"6 to 7\\\", \\\"ventilDepart\\\" : \\\"20051\\\" }\"";
var unescapedString = Regex.Unescape(escapedString);
returns the following
"{ "path" : "a.crx", "uniteDeVolume" : "g or ml", "unites" : "Acts/Volume", "nbIndevMin" : "20", "nbJours" : "6 to 7", "ventilDepart" : "20051" }"
Upvotes: 2
Reputation: 593
You can visit this link, It might help you
http://www.codeproject.com/Articles/371232/Escaping-in-Csharp-characters-strings-string-forma
Upvotes: 0