python json

使用Python的json模块的时候产生一个错误

python.dumps()

如果提供的参数里有中文,会产生如下的类似错误:

Traceback (most recent call last):

  File "<pyshell#43>", line 1, in <module>

    json.dumps([str])

  File "C:\Python26\lib\json\__init__.py", line 230, in dumps

    return _default_encoder.encode(obj)

  File "C:\Python26\lib\json\encoder.py", line 367, in encode

    chunks = list(self.iterencode(o))

  File "C:\Python26\lib\json\encoder.py", line 306, in _iterencode

    for chunk in self._iterencode_list(o, markers):

  File "C:\Python26\lib\json\encoder.py", line 204, in _iterencode_list

    for chunk in self._iterencode(value, markers):

  File "C:\Python26\lib\json\encoder.py", line 294, in _iterencode

    yield encoder(o)

UnicodeDecodeError: 'utf8' codec can't decode byte 0xbb in position 0: unexpected code byte

解决办法只需要设置ensure_ascii=False即可

posted @ 2011-01-17 04:44  macula7  阅读(609)  评论(0编辑  收藏  举报