次のコードでxmltodictを使用して、入力xmlファイルからjsonファイルを作成しようとしています
import io, xmltodict, json
infile = io.open(filename_xml, 'r')
outfile = io.open(filename_json, 'w')
o = xmltodict.parse( infile.read() )
json.dump( o , outfile )
最後の行で次のエラーが表示されます
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 182, in dump
fp.write(chunk)
TypeError: must be unicode, not str
エンコーディングを変更する必要があると思います。私の最初のxmlファイルはasciiのようです。これを機能させる方法について何か考えはありますか?ありがとう