小编lan*_*iac的帖子

如何修复json.dumps错误'utf8'编解码器无法解码位置2'的字节0xe0?

我有

import json 
a = {'code': 'exam', 'list': [{'note': '2', 'right': '2', 'question': 'Tr\xe0n V?n H\xf9ng', 'answers': ['etreetetetetret', 'reteretet', 'tedtetetet', 'etetetet']}], 'id': 1, 'level': 1}

json.dumps(a)
Run Code Online (Sandbox Code Playgroud)

===>错误:UnicodeDecodeError:'utf8'编解码器无法解码位置2的字节0xe0:无效

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/json/__init__.py", line 250, in dumps
    sort_keys=sort_keys, **kw).encode(obj)
  File "/usr/lib/python2.7/json/encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe0 in position 2: invalid continuation byte
Run Code Online (Sandbox Code Playgroud)

byte json python-2.7

2
推荐指数
1
解决办法
8568
查看次数

标签 统计

byte ×1

json ×1

python-2.7 ×1