我正在接收JSON字符串,將它傳遞給json.loads並以unicode字符串數組結尾。這一切都很好。一個數組中的字符串是:打印已解碼的JSON字符串
u'\xc3\x85sum'
現在使用的解碼(「utf-8」)解碼,而是我得到一個錯誤時,應翻譯成「ASUM」:
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
所以這工作得很好,但如果我把它做一個Unicode字符串作爲json.loads沒有我得到了同樣的錯誤:
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"
這工作,謝謝! – user2858835