escaping - How to obtain unescaped string value of Newtonsoft.Json deserialized value? -


i trying parse json objects made of (string,string) pairs. file parsing contains this. want ot emulate resjson behaviour.

{   "first_key": "first_value",   "unicode": "\u0040 @" } 

what

string path = @"d:\resjson\example.resjson"; string jsontext = file.readalltext(path);  idictionary<string, string> dict; try {     dict = jsonconvert.deserializeobject<idictionary<string, string>>(jsontext); } catch(exception ex) {   // log or } 

when obtain dict object,

foreach (var pair in _dict) {   string key = pair.key;   string value = pair.value;    console.writeline("key = '{0}', value = '{1}'", key, value); } 

this inputs me :

"key = 'first_key', value = 'first_value'" "key = 'unicode', value = '@ @'" 

once newtonsoft.json deserializes object, lose "\u0040" string , have no way of knowing how original file looked like. there way preserve character escaping ?

well, 1 simple idea escape backslashes in original text before passing parser:

dict = jsonconvert.deserializeobject<idictionary<string, string>>(            jsontext.replace(@"\", @"\\")); 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -