我收到一个 JSON 字符串,通过 json.loads 传递它并以一个 unicode 字符串数组结束。这一切都很好。数组中的字符串之一是:
u'\xc3\x85sum'
现在应该在使用 decode('utf8') 解码时转换为 'Åsum' 但我得到一个错误:
UnicodeEncodeError: 'charmap' codec can't encode character u'\x85' in position 1: character maps to <undefined>
为了测试出了什么问题,我做了以下
'Åsum'.encode('utf8')
'\xc3\x85sum'
print '\xc3\x85sum'.decode('utf8')
Åsum
所以效果很好,但是如果我将它作为 json.loads 做成一个 unicode 字符串,我会得到同样的错误:
print u'\xc3\x85sum'.decode('utf8')
UnicodeEncodeError: 'charmap' codec can't encode character u'\x85' in position 1: character maps to <undefined>
我尝试做 json.loads(jsonstring, encoding = 'uft8') 但这没有任何改变。
有没有办法解决它?使 json.loads 不使其成为 unicode 或按照我的要求使用 'utf8' 使其解码。
编辑:
我收到的原始字符串如下所示,或者导致问题的部分:
"\\u00c3\\u0085sum"