here is the problem, I want to dump and load windows paths in python under a unix system:
a = {"c":"a\b"}
b = json.dumps(a)
json.loads(b)
{u'c': u'a\x08'}
So, where did I go wrong?
here is the problem, I want to dump and load windows paths in python under a unix system:
a = {"c":"a\b"}
b = json.dumps(a)
json.loads(b)
{u'c': u'a\x08'}
So, where did I go wrong?
You failed to remember that the backslash character in a string literal can introduce an escpae sequence. "\b" represents the one-character string containing only a backspace.
The '\'
us being used for escaping b
here. You can use "a\\b"
or r"a\b"
to avoid this problem.
a = {"c":"a\\b"} # or a = {"c":r"a\b"}
b = json.dumps(a)
print json.loads(b)['c']
output
a\b