我有一个字符串,看起来像这样:
"{\\x22username\\x22:\\x229\\x22,\\x22password\\x22:\\x226\\x22,\\x22id\\x22:\\x222c8bfa56-f5d9\\x22, \\x22FName\\x22:\\x22AnkQcAJyrqpg\\x22}"
据我所知,\x22
是"
。那么,如何将其转换为键和值括有引号的可读性JSON呢?
发布于 2013-08-14 05:21:08
从string_escape
解码
>>> import json
>>> value = "{\\x22username\\x22:\\x229\\x22,\\x22password\\x22:\\x226\\x22,\\x22id\\x22:\\x222c8bfa56-f5d9\\x22, \\x22FName\\x22:\\x22AnkQcAJyrqpg\\x22}"
>>> value.decode('string_escape')
'{"username":"9","password":"6","id":"2c8bfa56-f5d9", "FName":"AnkQcAJyrqpg"}'
>>> json.loads(value.decode('string_escape'))
{u'username': u'9', u'password': u'6', u'id': u'2c8bfa56-f5d9', u'FName': u'AnkQcAJyrqpg'}
发布于 2018-06-08 14:02:13
对于Python3下的Unicode字符串,我发现:
value.encode('utf8').decode('unicode_escape')
发布于 2015-11-19 18:24:54
我知道这个问题被标记为python问题,但是如果有人想找一个可以在线编码这样的字符串的工具:
http://ddecode.com/hexdecoder
https://stackoverflow.com/questions/18219398
复制相似问题