我正在尝试将希伯来文内容从json解析为xml,从xml解析为json。 当我这么做的时候:
>>> from xml2json import json2xml
>>> json = {"test": "בדיקה"}
>>> json2xml(json)
我得到一个错误:
Traceback (most recent call last):
File "<pyshell#43>", line 1, in <module>
json2xml(json)
File "C:\Python27\lib\xml2json.py", line 182, in json2xml
return ET.tostring(elem)
File "C:\Python27\lib\xml\etree\ElementTree.py", line 1126, in tostring
ElementTree(element).write(file, encoding, method=method)
File "C:\Python27\lib\xml\etree\ElementTree.py", line 820, in write
serialize(write, self._root, encoding, qnames, namespaces)
File "C:\Python27\lib\xml\etree\ElementTree.py", line 937, in _serialize_xml
write(_escape_cdata(text, encoding))
File "C:\Python27\lib\xml\etree\ElementTree.py", line 1073, in _escape_cdata
return text.encode(encoding, "xmlcharrefreplace")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe1 in position 0: ordinal not in range(128)
我试着用utf8编码和解码,但似乎不起作用。。。 我使用的是python2.7
使用Unicode字符串,如下所示:
相关问题 更多 >
编程相关推荐