jsonファイルをロードしてから、後で解析しようとしています。しかし、出力では、私は 'u'文字を取得し続ける。 問題を解決するencoding = 'utf-8'でファイルを開こうとしました。 私はpython 2.7を使用しています。出力の 'u'文字を無視して乗り越えるための単純なアプローチまたは回避策がありますか?Python出力でUnicode文字を取り除く方法は?
import json
import io
with io.open('/tmp/install-report.json', encoding='utf-8') as json_data:
d = json.load(json_data)
print d
O/P
{u'install': {u'Status': u'In Progress...', u'StartedAt': 1471772544,}}
PS:私はこのポストSuppress the u'prefix indicating unicode' in python strings の谷行きましたが、それは、Python 2.7
:[**なし**](http://stackoverflow.com/questions/761361/suppress-the-uprefix-indicating-unicode-in-python-strings)を参照してください。 – Jan
なぜそれは問題ですか? –
Unicodeはこの問題とは関係ありません。これは、文字列でいっぱいの辞書のPython( 'repr()')表現です。 JSONなどの別の形式で表現したい場合は、その形式のエンコーダーを使用します。 – bobince