我正在研究简单的python脚本。不幸的是,我必须使用的一些数据存储如下:
trouble_string = '{\"N\": \"Centr\\u00e1lna nervov\\u00e1 s\\u00fastava\"}'
我想以以下格式转换字符串。
decoded_string = '{"N": "Centrálna nervová sústava"}'
我尝试过的
bytes(s, encoding='utf-8').decode(encoding='utf-16')
# outputs: '䌢湥牴畜〰ㅥ湬\u2061敮癲癯畜〰ㅥ猠畜〰慦瑳癡≡'
bytes(s, encoding='utf-16').decode(encoding='utf-8')
# outputs: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
trouble_string = '{\"N\": \"Centr\\u00e1lna nervov\\u00e1 s\\u00fastava\"}'
result = trouble_string.encode().decode("unicode-escape")